/*
* Copyright (C) 2010 Ixonos Plc.
- * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
+ * Copyright (C) 2011-2017 Philipp Spitzer, gregor herrmann, Stefan Stahl
*
* This file is part of ConfClerk.
*
#include <QPainter>
#include <QLabel>
+#include <conference.h>
+#include <application.h>
DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent): QWidget(aParent) {
connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
- connect(todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
+
+ configureNavigation();
}
}
+void DayNavigatorWidget::unsetDates() {
+ mStartDate= QDate();
+ mEndDate = QDate();
+ mCurDate = QDate();
+
+ configureNavigation();
+ emit(dateChanged(mCurDate));
+ this->update();
+}
+
+
void DayNavigatorWidget::configureNavigation() {
- prevDayButton->setDisabled(mCurDate == mStartDate);
- nextDayButton->setDisabled(mCurDate == mEndDate);
+ prevDayButton->setDisabled(!mStartDate.isValid() || mCurDate == mStartDate);
+ nextDayButton->setDisabled(!mEndDate.isValid() || mCurDate == mEndDate);
}
}
-void DayNavigatorWidget::todayButtonClicked() {
- setCurDate(QDate::currentDate());
-}
-
-
-void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
-{
+void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent) {
Q_UNUSED(aEvent);
-
- QString selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
+ QString selectedDateStr;
+ if (mCurDate.isValid()) {
+ selectedDateStr = mCurDate.toString("dddd\nyyyy-MM-dd");
+ bool hasConference = ((Application*) qApp)->hasActiveConference();
+ if (hasConference) {
+ Conference& conference = ((Application*) qApp)->activeConference();
+ if (conference.hasDisplayTimeShift() && conference.displayTimeShift() != 0) {
+ QTime shift(0, 0);
+ bool minus = conference.displayTimeShift() < 0;
+ shift = shift.addSecs(conference.displayTimeShift() * 60 * (minus ? -1 : 1));
+ selectedDateStr += " (" + (minus ? QString("-") : "+") + shift.toString("HH:mm") + ")";
+ }
+ }
+ } else {
+ selectedDateStr = tr("No date");
+ }
QPainter painter(this);
painter.save();
// rectangle only for the text
- int marginSize = 9;
- int buttonSize = 32;
-#ifdef MAEMO
- QRect q(y()-height()+1*marginSize+2.5*buttonSize, x(), height()-2*marginSize-2.5*buttonSize, width());
-#else
- QRect q(y()-height()+1*marginSize+2*buttonSize, x(), height()-2*marginSize-3*buttonSize, width());
-#endif
+ QRect q(-selectedDate->height()-selectedDate->y(), selectedDate->x(), selectedDate->height(), selectedDate->width());
painter.rotate(270);
// font size adjustion, static on maemo, dynamically otherwise
#ifdef MAEMO
qreal factor = 0.8;
#else
- qreal factor = (qreal) 2 * q.width() / painter.fontMetrics().width(selectedDateStr);
+#if QT_VERSION >= 0x050b00 // QT 5.11
+ auto dateStrWidth = painter.fontMetrics().horizontalAdvance(selectedDateStr);
+#else
+ auto dateStrWidth = painter.fontMetrics().width(selectedDateStr);
+#endif
+ qreal factor = (qreal) 2 * q.width() / dateStrWidth;
#endif
if (factor < 1) f.setPointSizeF(f.pointSizeF() * factor);
painter.setFont(f);