qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
loadhistorydialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "loadhistorydialog.h"
21 #include "ui_loadhistorydialog.h"
22 #include "src/model/ichatlog.h"
23 #include "src/nexus.h"
26 #include <QCalendarWidget>
27 #include <QDate>
28 #include <QTextCharFormat>
29 
30 LoadHistoryDialog::LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent)
31  : QDialog(parent)
32  , ui(new Ui::LoadHistoryDialog)
33  , chatLog(chatLog)
34 {
35  ui->setupUi(this);
36  highlightDates(QDate::currentDate().year(), QDate::currentDate().month());
37  connect(ui->fromDate, &QCalendarWidget::currentPageChanged, this,
39 }
40 
42  : QDialog(parent)
43  , ui(new Ui::LoadHistoryDialog)
44 {
45  ui->setupUi(this);
46 }
47 
49 {
50  delete ui;
51 }
52 
54 {
55 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
56  QDateTime res(ui->fromDate->selectedDate().startOfDay());
57 #else
58  QDateTime res(ui->fromDate->selectedDate());
59 #endif
60  if (res.date().month() != ui->fromDate->monthShown()
61  || res.date().year() != ui->fromDate->yearShown()) {
62  QDate newDate(ui->fromDate->yearShown(), ui->fromDate->monthShown(), 1);
63  res.setDate(newDate);
64  }
65 
66  return res;
67 }
68 
69 void LoadHistoryDialog::setTitle(const QString& title)
70 {
71  setWindowTitle(title);
72 }
73 
74 void LoadHistoryDialog::setInfoLabel(const QString& info)
75 {
76  ui->fromLabel->setText(info);
77 }
78 
79 void LoadHistoryDialog::highlightDates(int year, int month)
80 {
81  QDate monthStart(year, month, 1);
82  QDate monthEnd(year, month + 1, 1);
83 
84  // Max 31 days in a month
85  auto dateIdxs = chatLog->getDateIdxs(monthStart, 31);
86 
87  QTextCharFormat format;
88  format.setFontWeight(QFont::Bold);
89 
90  QCalendarWidget* calendar = ui->fromDate;
91  for (const auto& item : dateIdxs) {
92  if (item.date < monthEnd) {
93  calendar->setDateTextFormat(item.date, format);
94  }
95  }
96 }
profile.h
loadhistorydialog.h
history.h
ichatlog.h
LoadHistoryDialog::ui
Ui::LoadHistoryDialog * ui
Definition: loadhistorydialog.h:48
LoadHistoryDialog::LoadHistoryDialog
LoadHistoryDialog(const IChatLog *chatLog, QWidget *parent=nullptr)
Definition: loadhistorydialog.cpp:30
IChatLog
Definition: ichatlog.h:83
Ui
Definition: filetransferwidget.h:30
IChatLog::getDateIdxs
virtual std::vector< DateChatLogIdxPair > getDateIdxs(const QDate &startDate, size_t maxDates) const =0
Gets indexes for each new date starting at startDate.
LoadHistoryDialog::setInfoLabel
void setInfoLabel(const QString &info)
Definition: loadhistorydialog.cpp:74
LoadHistoryDialog::highlightDates
void highlightDates(int year, int month)
Definition: loadhistorydialog.cpp:79
LoadHistoryDialog
Definition: loadhistorydialog.h:31
LoadHistoryDialog::setTitle
void setTitle(const QString &title)
Definition: loadhistorydialog.cpp:69
LoadHistoryDialog::getFromDate
QDateTime getFromDate()
Definition: loadhistorydialog.cpp:53
LoadHistoryDialog::~LoadHistoryDialog
~LoadHistoryDialog()
Definition: loadhistorydialog.cpp:48
nexus.h
LoadHistoryDialog::chatLog
const IChatLog * chatLog
Definition: loadhistorydialog.h:49