source: src/gui/daynavigatorwidget.cpp @ a5e1f50

Last change on this file since a5e1f50 was a5e1f50, checked in by gregor herrmann <gregor@…>, 11 months ago

Clean up #includes.

(qtcreator is helpful but only partially.)

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl
4 *
5 * This file is part of ConfClerk.
6 *
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <QPainter>
22#include <QLabel>
23
24#include "daynavigatorwidget.h"
25#include "conference.h"
26#include "application.h"
27
28
29DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent): QWidget(aParent) {
30    setupUi(this);   
31
32    connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
33    connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
34
35    configureNavigation();
36}
37
38
39void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate) {
40    Q_ASSERT(aStartDate.isValid() && aEndDate.isValid() && aStartDate<=aEndDate);
41
42    mStartDate = aStartDate;
43    mEndDate = aEndDate;
44
45    if (!mCurDate.isValid()) mCurDate = mStartDate;
46    // if mCurDate is out of range, set it to mstartDate
47    else if (mCurDate < mStartDate || mCurDate > mEndDate) mCurDate = mStartDate;
48
49    configureNavigation();
50    emit(dateChanged(mCurDate));
51    this->update();
52}
53
54
55void DayNavigatorWidget::setCurDate(const QDate& curDate) {
56    Q_ASSERT(curDate.isValid());
57    if (curDate == mCurDate) return;
58
59    if (!mStartDate.isValid()) {
60        // the start and end date have not been set
61        mStartDate = curDate;
62        mEndDate = curDate;
63        mCurDate = curDate;
64    }
65
66    else if (curDate < mStartDate) mCurDate = mStartDate;
67    else if (curDate > mEndDate) mCurDate = mEndDate;
68    else mCurDate = curDate;
69
70    configureNavigation();
71    emit(dateChanged(mCurDate));
72    this->update();
73}
74
75
76void DayNavigatorWidget::unsetDates() {
77    mStartDate= QDate();
78    mEndDate = QDate();
79    mCurDate = QDate();
80
81    configureNavigation();
82    emit(dateChanged(mCurDate));
83    this->update();
84}
85
86
87void DayNavigatorWidget::configureNavigation() {
88    prevDayButton->setDisabled(!mStartDate.isValid() || mCurDate == mStartDate);
89    nextDayButton->setDisabled(!mEndDate.isValid() || mCurDate == mEndDate);
90}
91
92
93void DayNavigatorWidget::prevDayButtonClicked() {
94    if(mCurDate <= mStartDate) return;
95    mCurDate = mCurDate.addDays(-1);
96    configureNavigation();
97    emit(dateChanged(mCurDate));
98    this->update();
99}
100
101
102void DayNavigatorWidget::nextDayButtonClicked() {
103    if(mCurDate >= mEndDate) return;
104    mCurDate = mCurDate.addDays(1);
105    configureNavigation();
106    emit(dateChanged(mCurDate));
107    this->update();
108}
109
110
111void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent) {
112    Q_UNUSED(aEvent);
113    QString selectedDateStr;
114    if (mCurDate.isValid()) {
115        selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
116        bool hasConference = ((Application*) qApp)->hasActiveConference();
117        if (hasConference) {
118            Conference& conference = ((Application*) qApp)->activeConference();
119            if (conference.hasDisplayTimeShift() && conference.displayTimeShift() != 0) {
120                QTime shift(0, 0);
121                bool minus = conference.displayTimeShift() < 0;
122                shift = shift.addSecs(conference.displayTimeShift() * 60 * (minus ? -1 : 1));
123                selectedDateStr += " (" + (minus ? QString("-") : "+") + shift.toString("HH:mm") + ")";
124            }
125        }
126    } else {
127        selectedDateStr = tr("No date");
128    }
129    QPainter painter(this);
130    painter.save();
131
132    // rectangle only for the text
133    QRect q(-selectedDate->height()-selectedDate->y(), selectedDate->x(), selectedDate->height(), selectedDate->width());
134    painter.rotate(270);
135
136    // font size adjustion, static on maemo, dynamically otherwise
137    QFont f = painter.font();
138#ifdef MAEMO
139    qreal factor = 0.8;
140#else
141#if QT_VERSION >= 0x050b00 // QT 5.11
142    auto dateStrWidth = painter.fontMetrics().horizontalAdvance(selectedDateStr);
143#else
144    auto dateStrWidth = painter.fontMetrics().width(selectedDateStr);
145#endif
146    qreal factor = (qreal) 2 * q.width() / dateStrWidth;
147#endif
148    if (factor < 1) f.setPointSizeF(f.pointSizeF() * factor);
149    painter.setFont(f);
150
151    painter.drawText(q, Qt::AlignCenter, selectedDateStr);
152    painter.restore();
153}
Note: See TracBrowser for help on using the repository browser.