root/trunk/qt4-gui/src/widgets/calendar.cpp

Revision 6469, 2.8 kB (checked in by flynd, 4 months ago)

QCalendarWidget::updateCell() and QCalendarWidget::updateCells() does not exist in Qt 4.3.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 2007 Licq developers
5 *
6 * Licq is free 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 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq 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 Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include "calendar.h"
22
23#include "config.h"
24
25#ifdef __GLIBC__
26#include <langinfo.h>
27#endif
28
29#include <QPainter>
30#include <QTextCharFormat>
31
32
33using namespace LicqQtGui;
34/* TRANSLATOR LicqQtGui::Calendar */
35
36Calendar::Calendar(QWidget* parent)
37    : QCalendarWidget(parent)
38{
39#ifdef __GLIBC__
40  // Non-standard locale parameter available in gnu libc only
41  int firstday = *nl_langinfo(_NL_TIME_FIRST_WEEKDAY);
42  if (firstday > 0)
43  {
44    // locale data uses: 1=Sunday, 2=Monday..., 7=Saturday
45    // Qt data uses: 1=Monday, 2=Tuesday..., 7=Sunday
46    firstday -= 1;
47    if (firstday == 0)
48      firstday = Qt::Sunday;
49    setFirstDayOfWeek(static_cast<Qt::DayOfWeek>(firstday));
50  }
51  else
52#endif
53    setFirstDayOfWeek(Qt::Monday);
54}
55
56void Calendar::markDate(const QDate& date)
57{
58  QTextCharFormat textFormat = dateTextFormat(date);
59  // Mark dates with bold
60  textFormat.setFontWeight(QFont::Bold);
61  // Background must be transparent to not overwrite the elipse
62  textFormat.setBackground(Qt::transparent);
63  setDateTextFormat(date, textFormat);
64}
65
66void Calendar::addMatch(const QDate& date)
67{
68  if (myMatches.contains(date))
69    return;
70
71  myMatches.append(date);
72#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
73  updateCell(date);
74#else
75  update();
76#endif
77}
78
79void Calendar::clearMatches()
80{
81  myMatches.clear();
82#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
83  updateCells();
84#else
85  update();
86#endif
87}
88
89void Calendar::paintCell(QPainter* painter, const QRect& rect, const QDate& date) const
90{
91  QTextCharFormat format = dateTextFormat(date);
92  if (format.fontWeight() == QFont::Bold)
93  {
94    painter->save();
95    const int adjust = 1;
96    QRect center = rect.adjusted(adjust, adjust, -adjust, -adjust);
97    painter->setPen(Qt::NoPen);
98    painter->setRenderHints(painter->renderHints() | QPainter::Antialiasing);
99    painter->setBrush(myMatches.contains(date) ? Qt::green : Qt::yellow);
100    painter->drawEllipse(center);
101    painter->restore();
102  }
103
104  QCalendarWidget::paintCell(painter, rect, date);
105}
Note: See TracBrowser for help on using the browser.