| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcalendarwidget.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | enum { | - | ||||||||||||
| 10 | RowCount = 6, | - | ||||||||||||
| 11 | ColumnCount = 7, | - | ||||||||||||
| 12 | HeaderColumn = 0, | - | ||||||||||||
| 13 | HeaderRow = 0, | - | ||||||||||||
| 14 | MinimumDayOffset = 1 | - | ||||||||||||
| 15 | }; | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | namespace { | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | static QString formatNumber(int number, int fieldWidth) | - | ||||||||||||
| 20 | { | - | ||||||||||||
| 21 | return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0')); | - | ||||||||||||
| 22 | } | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | class QCalendarDateSectionValidator | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | public: | - | ||||||||||||
| 27 | - | |||||||||||||
| 28 | enum Section { | - | ||||||||||||
| 29 | NextSection, | - | ||||||||||||
| 30 | ThisSection, | - | ||||||||||||
| 31 | PrevSection | - | ||||||||||||
| 32 | }; | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | QCalendarDateSectionValidator() {} | - | ||||||||||||
| 35 | virtual ~QCalendarDateSectionValidator() {} | - | ||||||||||||
| 36 | virtual Section handleKey(int key) = 0; | - | ||||||||||||
| 37 | virtual QDate applyToDate(const QDate &date) const = 0; | - | ||||||||||||
| 38 | virtual void setDate(const QDate &date) = 0; | - | ||||||||||||
| 39 | virtual QString text() const = 0; | - | ||||||||||||
| 40 | virtual QString text(const QDate &date, int repeat) const = 0; | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | QLocale m_locale; | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | protected: | - | ||||||||||||
| 45 | static QString highlightString(const QString &str, int pos); | - | ||||||||||||
| 46 | private: | - | ||||||||||||
| 47 | }; | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | QString QCalendarDateSectionValidator::highlightString(const QString &str, int pos) | - | ||||||||||||
| 50 | { | - | ||||||||||||
| 51 | if (pos == 0) | - | ||||||||||||
| 52 | return QLatin1String("<b>") + str + QLatin1String("</b>"); | - | ||||||||||||
| 53 | int startPos = str.length() - pos; | - | ||||||||||||
| 54 | return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>"); | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | } | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | class QCalendarDayValidator : public QCalendarDateSectionValidator | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | public: | - | ||||||||||||
| 62 | QCalendarDayValidator(); | - | ||||||||||||
| 63 | virtual Section handleKey(int key) override; | - | ||||||||||||
| 64 | virtual QDate applyToDate(const QDate &date) const override; | - | ||||||||||||
| 65 | virtual void setDate(const QDate &date) override; | - | ||||||||||||
| 66 | virtual QString text() const override; | - | ||||||||||||
| 67 | virtual QString text(const QDate &date, int repeat) const override; | - | ||||||||||||
| 68 | private: | - | ||||||||||||
| 69 | int m_pos; | - | ||||||||||||
| 70 | int m_day; | - | ||||||||||||
| 71 | int m_oldDay; | - | ||||||||||||
| 72 | }; | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | QCalendarDayValidator::QCalendarDayValidator() | - | ||||||||||||
| 75 | : QCalendarDateSectionValidator(), m_pos(0), m_day(1), m_oldDay(1) | - | ||||||||||||
| 76 | { | - | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | QCalendarDateSectionValidator::Section QCalendarDayValidator::handleKey(int key) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | if (key == Qt::Key_Right || key == Qt::Key_Left) { | - | ||||||||||||
| 82 | m_pos = 0; | - | ||||||||||||
| 83 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 84 | } else if (key == Qt::Key_Up) { | - | ||||||||||||
| 85 | m_pos = 0; | - | ||||||||||||
| 86 | ++m_day; | - | ||||||||||||
| 87 | if (m_day > 31) | - | ||||||||||||
| 88 | m_day = 1; | - | ||||||||||||
| 89 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 90 | } else if (key == Qt::Key_Down) { | - | ||||||||||||
| 91 | m_pos = 0; | - | ||||||||||||
| 92 | --m_day; | - | ||||||||||||
| 93 | if (m_day < 1) | - | ||||||||||||
| 94 | m_day = 31; | - | ||||||||||||
| 95 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 96 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) { | - | ||||||||||||
| 97 | --m_pos; | - | ||||||||||||
| 98 | if (m_pos < 0) | - | ||||||||||||
| 99 | m_pos = 1; | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | if (m_pos == 0) | - | ||||||||||||
| 102 | m_day = m_oldDay; | - | ||||||||||||
| 103 | else | - | ||||||||||||
| 104 | m_day = m_day / 10; | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | - | |||||||||||||
| 107 | if (m_pos == 0) | - | ||||||||||||
| 108 | return QCalendarDateSectionValidator::PrevSection; | - | ||||||||||||
| 109 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | if (key < Qt::Key_0 || key > Qt::Key_9) | - | ||||||||||||
| 112 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 113 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||
| 114 | if (m_pos == 0) | - | ||||||||||||
| 115 | m_day = pressedKey; | - | ||||||||||||
| 116 | else | - | ||||||||||||
| 117 | m_day = m_day % 10 * 10 + pressedKey; | - | ||||||||||||
| 118 | if (m_day > 31) | - | ||||||||||||
| 119 | m_day = 31; | - | ||||||||||||
| 120 | ++m_pos; | - | ||||||||||||
| 121 | if (m_pos > 1) { | - | ||||||||||||
| 122 | m_pos = 0; | - | ||||||||||||
| 123 | return QCalendarDateSectionValidator::NextSection; | - | ||||||||||||
| 124 | } | - | ||||||||||||
| 125 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 126 | } | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | QDate QCalendarDayValidator::applyToDate(const QDate &date) const | - | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | int day = m_day; | - | ||||||||||||
| 131 | if (day < 1) | - | ||||||||||||
| 132 | day = 1; | - | ||||||||||||
| 133 | else if (day > 31) | - | ||||||||||||
| 134 | day = 31; | - | ||||||||||||
| 135 | if (day > date.daysInMonth()) | - | ||||||||||||
| 136 | day = date.daysInMonth(); | - | ||||||||||||
| 137 | return QDate(date.year(), date.month(), day); | - | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | void QCalendarDayValidator::setDate(const QDate &date) | - | ||||||||||||
| 141 | { | - | ||||||||||||
| 142 | m_day = m_oldDay = date.day(); | - | ||||||||||||
| 143 | m_pos = 0; | - | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | QString QCalendarDayValidator::text() const | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | return highlightString(formatNumber(m_day, 2), m_pos); | - | ||||||||||||
| 149 | } | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | QString QCalendarDayValidator::text(const QDate &date, int repeat) const | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | if (repeat <= 1) { | - | ||||||||||||
| 154 | return QString::number(date.day()); | - | ||||||||||||
| 155 | } else if (repeat == 2) { | - | ||||||||||||
| 156 | return formatNumber(date.day(), 2); | - | ||||||||||||
| 157 | } else if (repeat == 3) { | - | ||||||||||||
| 158 | return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat); | - | ||||||||||||
| 159 | } else { | - | ||||||||||||
| 160 | return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat); | - | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | - | |||||||||||||
| 165 | - | |||||||||||||
| 166 | class QCalendarMonthValidator : public QCalendarDateSectionValidator | - | ||||||||||||
| 167 | { | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | public: | - | ||||||||||||
| 170 | QCalendarMonthValidator(); | - | ||||||||||||
| 171 | virtual Section handleKey(int key) override; | - | ||||||||||||
| 172 | virtual QDate applyToDate(const QDate &date) const override; | - | ||||||||||||
| 173 | virtual void setDate(const QDate &date) override; | - | ||||||||||||
| 174 | virtual QString text() const override; | - | ||||||||||||
| 175 | virtual QString text(const QDate &date, int repeat) const override; | - | ||||||||||||
| 176 | private: | - | ||||||||||||
| 177 | int m_pos; | - | ||||||||||||
| 178 | int m_month; | - | ||||||||||||
| 179 | int m_oldMonth; | - | ||||||||||||
| 180 | }; | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | QCalendarMonthValidator::QCalendarMonthValidator() | - | ||||||||||||
| 183 | : QCalendarDateSectionValidator(), m_pos(0), m_month(1), m_oldMonth(1) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | QCalendarDateSectionValidator::Section QCalendarMonthValidator::handleKey(int key) | - | ||||||||||||
| 188 | { | - | ||||||||||||
| 189 | if (key == Qt::Key_Right || key == Qt::Key_Left) { | - | ||||||||||||
| 190 | m_pos = 0; | - | ||||||||||||
| 191 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 192 | } else if (key == Qt::Key_Up) { | - | ||||||||||||
| 193 | m_pos = 0; | - | ||||||||||||
| 194 | ++m_month; | - | ||||||||||||
| 195 | if (m_month > 12) | - | ||||||||||||
| 196 | m_month = 1; | - | ||||||||||||
| 197 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 198 | } else if (key == Qt::Key_Down) { | - | ||||||||||||
| 199 | m_pos = 0; | - | ||||||||||||
| 200 | --m_month; | - | ||||||||||||
| 201 | if (m_month < 1) | - | ||||||||||||
| 202 | m_month = 12; | - | ||||||||||||
| 203 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 204 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) { | - | ||||||||||||
| 205 | --m_pos; | - | ||||||||||||
| 206 | if (m_pos < 0) | - | ||||||||||||
| 207 | m_pos = 1; | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | if (m_pos == 0) | - | ||||||||||||
| 210 | m_month = m_oldMonth; | - | ||||||||||||
| 211 | else | - | ||||||||||||
| 212 | m_month = m_month / 10; | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | - | |||||||||||||
| 215 | if (m_pos == 0) | - | ||||||||||||
| 216 | return QCalendarDateSectionValidator::PrevSection; | - | ||||||||||||
| 217 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 218 | } | - | ||||||||||||
| 219 | if (key < Qt::Key_0 || key > Qt::Key_9) | - | ||||||||||||
| 220 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 221 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||
| 222 | if (m_pos == 0) | - | ||||||||||||
| 223 | m_month = pressedKey; | - | ||||||||||||
| 224 | else | - | ||||||||||||
| 225 | m_month = m_month % 10 * 10 + pressedKey; | - | ||||||||||||
| 226 | if (m_month > 12) | - | ||||||||||||
| 227 | m_month = 12; | - | ||||||||||||
| 228 | ++m_pos; | - | ||||||||||||
| 229 | if (m_pos > 1) { | - | ||||||||||||
| 230 | m_pos = 0; | - | ||||||||||||
| 231 | return QCalendarDateSectionValidator::NextSection; | - | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 234 | } | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | QDate QCalendarMonthValidator::applyToDate(const QDate &date) const | - | ||||||||||||
| 237 | { | - | ||||||||||||
| 238 | int month = m_month; | - | ||||||||||||
| 239 | if (month < 1) | - | ||||||||||||
| 240 | month = 1; | - | ||||||||||||
| 241 | else if (month > 12) | - | ||||||||||||
| 242 | month = 12; | - | ||||||||||||
| 243 | QDate newDate(date.year(), m_month, 1); | - | ||||||||||||
| 244 | int day = date.day(); | - | ||||||||||||
| 245 | if (day > newDate.daysInMonth()) | - | ||||||||||||
| 246 | day = newDate.daysInMonth(); | - | ||||||||||||
| 247 | return QDate(date.year(), month, day); | - | ||||||||||||
| 248 | } | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | void QCalendarMonthValidator::setDate(const QDate &date) | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | m_month = m_oldMonth = date.month(); | - | ||||||||||||
| 253 | m_pos = 0; | - | ||||||||||||
| 254 | } | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | QString QCalendarMonthValidator::text() const | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | return highlightString(formatNumber(m_month, 2), m_pos); | - | ||||||||||||
| 259 | } | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | QString QCalendarMonthValidator::text(const QDate &date, int repeat) const | - | ||||||||||||
| 262 | { | - | ||||||||||||
| 263 | if (repeat <= 1) { | - | ||||||||||||
| 264 | return QString::number(date.month()); | - | ||||||||||||
| 265 | } else if (repeat == 2) { | - | ||||||||||||
| 266 | return formatNumber(date.month(), 2); | - | ||||||||||||
| 267 | } else if (repeat == 3) { | - | ||||||||||||
| 268 | return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat); | - | ||||||||||||
| 269 | } else { | - | ||||||||||||
| 270 | return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat); | - | ||||||||||||
| 271 | } | - | ||||||||||||
| 272 | } | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | - | |||||||||||||
| 275 | - | |||||||||||||
| 276 | class QCalendarYearValidator : public QCalendarDateSectionValidator | - | ||||||||||||
| 277 | { | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | public: | - | ||||||||||||
| 280 | QCalendarYearValidator(); | - | ||||||||||||
| 281 | virtual Section handleKey(int key) override; | - | ||||||||||||
| 282 | virtual QDate applyToDate(const QDate &date) const override; | - | ||||||||||||
| 283 | virtual void setDate(const QDate &date) override; | - | ||||||||||||
| 284 | virtual QString text() const override; | - | ||||||||||||
| 285 | virtual QString text(const QDate &date, int repeat) const override; | - | ||||||||||||
| 286 | private: | - | ||||||||||||
| 287 | int pow10(int n); | - | ||||||||||||
| 288 | int m_pos; | - | ||||||||||||
| 289 | int m_year; | - | ||||||||||||
| 290 | int m_oldYear; | - | ||||||||||||
| 291 | }; | - | ||||||||||||
| 292 | - | |||||||||||||
| 293 | QCalendarYearValidator::QCalendarYearValidator() | - | ||||||||||||
| 294 | : QCalendarDateSectionValidator(), m_pos(0), m_year(2000), m_oldYear(2000) | - | ||||||||||||
| 295 | { | - | ||||||||||||
| 296 | } | - | ||||||||||||
| 297 | - | |||||||||||||
| 298 | int QCalendarYearValidator::pow10(int n) | - | ||||||||||||
| 299 | { | - | ||||||||||||
| 300 | int power = 1; | - | ||||||||||||
| 301 | for (int i = 0; i < n; i++) | - | ||||||||||||
| 302 | power *= 10; | - | ||||||||||||
| 303 | return power; | - | ||||||||||||
| 304 | } | - | ||||||||||||
| 305 | - | |||||||||||||
| 306 | QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey(int key) | - | ||||||||||||
| 307 | { | - | ||||||||||||
| 308 | if (key == Qt::Key_Right || key == Qt::Key_Left) { | - | ||||||||||||
| 309 | m_pos = 0; | - | ||||||||||||
| 310 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 311 | } else if (key == Qt::Key_Up) { | - | ||||||||||||
| 312 | m_pos = 0; | - | ||||||||||||
| 313 | ++m_year; | - | ||||||||||||
| 314 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 315 | } else if (key == Qt::Key_Down) { | - | ||||||||||||
| 316 | m_pos = 0; | - | ||||||||||||
| 317 | --m_year; | - | ||||||||||||
| 318 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 319 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) { | - | ||||||||||||
| 320 | --m_pos; | - | ||||||||||||
| 321 | if (m_pos < 0) | - | ||||||||||||
| 322 | m_pos = 3; | - | ||||||||||||
| 323 | - | |||||||||||||
| 324 | int pow = pow10(m_pos); | - | ||||||||||||
| 325 | m_year = m_oldYear / pow * pow + m_year % (pow * 10) / 10; | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | if (m_pos == 0) | - | ||||||||||||
| 328 | return QCalendarDateSectionValidator::PrevSection; | - | ||||||||||||
| 329 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 330 | } | - | ||||||||||||
| 331 | if (key < Qt::Key_0 || key > Qt::Key_9) | - | ||||||||||||
| 332 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 333 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||
| 334 | int pow = pow10(m_pos); | - | ||||||||||||
| 335 | m_year = m_year / (pow * 10) * (pow * 10) + m_year % pow * 10 + pressedKey; | - | ||||||||||||
| 336 | ++m_pos; | - | ||||||||||||
| 337 | if (m_pos > 3) { | - | ||||||||||||
| 338 | m_pos = 0; | - | ||||||||||||
| 339 | return QCalendarDateSectionValidator::NextSection; | - | ||||||||||||
| 340 | } | - | ||||||||||||
| 341 | return QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 342 | } | - | ||||||||||||
| 343 | - | |||||||||||||
| 344 | QDate QCalendarYearValidator::applyToDate(const QDate &date) const | - | ||||||||||||
| 345 | { | - | ||||||||||||
| 346 | int year = m_year; | - | ||||||||||||
| 347 | if (year < 1) | - | ||||||||||||
| 348 | year = 1; | - | ||||||||||||
| 349 | QDate newDate(year, date.month(), 1); | - | ||||||||||||
| 350 | int day = date.day(); | - | ||||||||||||
| 351 | if (day > newDate.daysInMonth()) | - | ||||||||||||
| 352 | day = newDate.daysInMonth(); | - | ||||||||||||
| 353 | return QDate(year, date.month(), day); | - | ||||||||||||
| 354 | } | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | void QCalendarYearValidator::setDate(const QDate &date) | - | ||||||||||||
| 357 | { | - | ||||||||||||
| 358 | m_year = m_oldYear = date.year(); | - | ||||||||||||
| 359 | m_pos = 0; | - | ||||||||||||
| 360 | } | - | ||||||||||||
| 361 | - | |||||||||||||
| 362 | QString QCalendarYearValidator::text() const | - | ||||||||||||
| 363 | { | - | ||||||||||||
| 364 | return highlightString(formatNumber(m_year, 4), m_pos); | - | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | - | |||||||||||||
| 367 | QString QCalendarYearValidator::text(const QDate &date, int repeat) const | - | ||||||||||||
| 368 | { | - | ||||||||||||
| 369 | if (repeat < 4) | - | ||||||||||||
| 370 | return formatNumber(date.year() % 100, 2); | - | ||||||||||||
| 371 | return QString::number(date.year()); | - | ||||||||||||
| 372 | } | - | ||||||||||||
| 373 | - | |||||||||||||
| 374 | - | |||||||||||||
| 375 | - | |||||||||||||
| 376 | struct SectionToken { | - | ||||||||||||
| 377 | constexpr SectionToken(QCalendarDateSectionValidator *v, int rep) | - | ||||||||||||
| 378 | : validator(v), repeat(rep) {} | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | QCalendarDateSectionValidator *validator; | - | ||||||||||||
| 381 | int repeat; | - | ||||||||||||
| 382 | }; | - | ||||||||||||
| 383 | } | - | ||||||||||||
| 384 | template<> class QTypeInfo<SectionToken > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(SectionToken)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< SectionToken >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(SectionToken) }; static inline const char *name() { return "SectionToken"; } }; | - | ||||||||||||
| 385 | namespace { | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | class QCalendarDateValidator | - | ||||||||||||
| 388 | { | - | ||||||||||||
| 389 | public: | - | ||||||||||||
| 390 | QCalendarDateValidator(); | - | ||||||||||||
| 391 | ~QCalendarDateValidator(); | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | void handleKeyEvent(QKeyEvent *keyEvent); | - | ||||||||||||
| 394 | QString currentText() const; | - | ||||||||||||
| 395 | QDate currentDate() const { return m_currentDate; } | - | ||||||||||||
| 396 | void setFormat(const QString &format); | - | ||||||||||||
| 397 | void setInitialDate(const QDate &date); | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | void setLocale(const QLocale &locale); | - | ||||||||||||
| 400 | - | |||||||||||||
| 401 | private: | - | ||||||||||||
| struct SectionToken { | ||||||||||||||
| SectionToken(QCalendarDateSectionValidator *val, int rep): | ||||||||||||||
| 402 | validator(val), repeat(rep) {} | - | ||||||||||||
| QCalendarDateSectionValidator *validator; | ||||||||||||||
| int repeat; | ||||||||||||||
| };void toNextToken(); | ||||||||||||||
| 403 | void toPreviousToken(); | - | ||||||||||||
| 404 | void applyToDate(); | - | ||||||||||||
| 405 | - | |||||||||||||
| 406 | int countRepeat(const QString &str, int index) const; | - | ||||||||||||
| 407 | void clear(); | - | ||||||||||||
| 408 | - | |||||||||||||
| 409 | QStringList m_separators; | - | ||||||||||||
| 410 | QListstd::vector<SectionToken*>> m_tokens; | - | ||||||||||||
| 411 | QCalendarYearValidator m_yearValidator; | - | ||||||||||||
| 412 | QCalendarMonthValidator m_monthValidator; | - | ||||||||||||
| 413 | QCalendarDayValidator m_dayValidator; | - | ||||||||||||
| 414 | - | |||||||||||||
| 415 | SectionToken *int m_currentToken; | - | ||||||||||||
| 416 | - | |||||||||||||
| 417 | QDate m_initialDate; | - | ||||||||||||
| 418 | QDate m_currentDate; | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | QCalendarDateSectionValidator::Section m_lastSectionMove; | - | ||||||||||||
| 421 | }; | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | QCalendarDateValidator::QCalendarDateValidator() | - | ||||||||||||
| 424 | : m_currentToken(nullptr(-1), | - | ||||||||||||
| 425 | m_initialDate(QDate::currentDate()), | - | ||||||||||||
| 426 | m_currentDate(m_initialDate), | - | ||||||||||||
| 427 | m_lastSectionMove(QCalendarDateSectionValidator::ThisSection) | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | } never executed: end of block | 0 | ||||||||||||
| 430 | - | |||||||||||||
| 431 | void QCalendarDateValidator::setLocale(const QLocale &locale) | - | ||||||||||||
| 432 | { | - | ||||||||||||
| 433 | m_yearValidator.m_locale = locale; | - | ||||||||||||
| 434 | m_monthValidator.m_locale = locale; | - | ||||||||||||
| 435 | m_dayValidator.m_locale = locale; | - | ||||||||||||
| 436 | } | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | QCalendarDateValidator::~QCalendarDateValidator() | - | ||||||||||||
| 439 | { | - | ||||||||||||
| 440 | clear(); | - | ||||||||||||
| 441 | } | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | - | |||||||||||||
| 444 | int QCalendarDateValidator::countRepeat(const QString &str, int index) const | - | ||||||||||||
| 445 | { | - | ||||||||||||
| 446 | ((!(index >= 0 && index < str.size())) ? qt_assert("index >= 0 && index < str.size()",__FILE__,491503) : qt_noop()); | - | ||||||||||||
| 447 | int count = 1; | - | ||||||||||||
| 448 | const QChar ch = str.at(index); | - | ||||||||||||
| 449 | while (index + count < str.size() && str.at(index + count) == ch) | - | ||||||||||||
| 450 | ++count; | - | ||||||||||||
| 451 | return count; | - | ||||||||||||
| 452 | } | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | void QCalendarDateValidator::setInitialDate(const QDate &date) | - | ||||||||||||
| 455 | { | - | ||||||||||||
| 456 | m_yearValidator.setDate(date); | - | ||||||||||||
| 457 | m_monthValidator.setDate(date); | - | ||||||||||||
| 458 | m_dayValidator.setDate(date); | - | ||||||||||||
| 459 | m_initialDate = date; | - | ||||||||||||
| 460 | m_currentDate = date; | - | ||||||||||||
| 461 | m_lastSectionMove = QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||
| 462 | } | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | QString QCalendarDateValidator::currentText() const | - | ||||||||||||
| 465 | { | - | ||||||||||||
| 466 | QString str; | - | ||||||||||||
| 467 | QStringListIterator itSep(const int numSeps = m_separators); | - | ||||||||||||
| QListIterator<SectionToken *> itTok.size(); | ||||||||||||||
| 468 | const int numTokens = int(m_tokens); | - | ||||||||||||
| while (itSep.hasNext())size()); | ||||||||||||||
| 469 | for (int i = 0; i < numSeps
| 0 | ||||||||||||
| 470 | str += itSepm_separators.next();at(i); | - | ||||||||||||
| 471 | if (itTok.hasNext())i < numTokens
| 0 | ||||||||||||
| 472 | const SectionToken *token = itTok.next(); | - | ||||||||||||
| QCalendarDateSectionValidator *validator&token = token->validator;m_tokens[i]; | ||||||||||||||
| 473 | if (m_currentTokeni
| 0 | ||||||||||||
| 474 | str += token.validator->text(); never executed: str += token.validator->text(); | 0 | ||||||||||||
| 475 | else | - | ||||||||||||
| 476 | str += token.validator->text(m_currentDate, token->.repeat); never executed: str += token.validator->text(m_currentDate, token.repeat); | 0 | ||||||||||||
| 477 | } | - | ||||||||||||
| 478 | } never executed: end of block | 0 | ||||||||||||
| 479 | return never executed: str;return str;never executed: return str; | 0 | ||||||||||||
| 480 | } | - | ||||||||||||
| 481 | - | |||||||||||||
| 482 | void QCalendarDateValidator::clear() | - | ||||||||||||
| 483 | { | - | ||||||||||||
| 484 | QListIterator<SectionToken *> it(m_tokens); | - | ||||||||||||
| while (it.hasNext()) | ||||||||||||||
| delete it.next();m_tokens.clear(); | ||||||||||||||
| 485 | m_separators.clear(); | - | ||||||||||||
| 486 | - | |||||||||||||
| 487 | m_currentToken = 0-1; | - | ||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||
| 489 | - | |||||||||||||
| 490 | void QCalendarDateValidator::setFormat(const QString &format) | - | ||||||||||||
| 491 | { | - | ||||||||||||
| 492 | clear(); | - | ||||||||||||
| 493 | - | |||||||||||||
| 494 | int pos = 0; | - | ||||||||||||
| 495 | const QLatin1Char quote('\''); | - | ||||||||||||
| 496 | bool quoting = false; | - | ||||||||||||
| 497 | QString separator; | - | ||||||||||||
| 498 | while (pos < format.size()
| 0 | ||||||||||||
| 499 | QStringconst QStringRef mid = format.midmidRef(pos); | - | ||||||||||||
| 500 | int offset = 1; | - | ||||||||||||
| 501 | - | |||||||||||||
| 502 | if (mid.startsWith(quote)
| 0 | ||||||||||||
| 503 | quoting = !quoting; | - | ||||||||||||
| 504 | } never executed: else {end of block | 0 | ||||||||||||
| 505 | const QChar nextChar = format.at(pos); | - | ||||||||||||
| 506 | if (quoting
| 0 | ||||||||||||
| 507 | separator += nextChar; | - | ||||||||||||
| 508 | quoting = false; | - | ||||||||||||
| 509 | } never executed: else {end of block | 0 | ||||||||||||
| 510 | SectionTokenQCalendarDateSectionValidator *tokenvalidator = 0; | - | ||||||||||||
| 511 | if (nextChar == QLatin1Char('d')
| 0 | ||||||||||||
| 512 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||
| 513 | tokenvalidator = new SectionToken(&m_dayValidator, offset);; | - | ||||||||||||
| 514 | } never executed: else if (nextChar == QLatin1Char('M')end of block
| 0 | ||||||||||||
| 515 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||
| 516 | tokenvalidator = new SectionToken(&m_monthValidator, offset);; | - | ||||||||||||
| 517 | } never executed: else if (nextChar == QLatin1Char('y')end of block
| 0 | ||||||||||||
| 518 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||
| 519 | tokenvalidator = new SectionToken(&m_yearValidator, offset);; | - | ||||||||||||
| 520 | } never executed: else {end of block | 0 | ||||||||||||
| 521 | separator += nextChar; | - | ||||||||||||
| 522 | } never executed: end of block | 0 | ||||||||||||
| 523 | if (tokenvalidator
| 0 | ||||||||||||
| 524 | m_tokens.appendpush_back(token);SectionToken(validator, offset)); | - | ||||||||||||
| 525 | m_separators.append(separator); | - | ||||||||||||
| 526 | separator = QString(); | - | ||||||||||||
| 527 | if (!(m_currentToken < 0
| 0 | ||||||||||||
| 528 | m_currentToken = tokenint(m_tokens.size()) - 1; never executed: m_currentToken = int(m_tokens.size()) - 1; | 0 | ||||||||||||
| 529 | - | |||||||||||||
| 530 | } never executed: end of block | 0 | ||||||||||||
| 531 | } never executed: end of block | 0 | ||||||||||||
| 532 | } | - | ||||||||||||
| 533 | pos += offset; | - | ||||||||||||
| 534 | } never executed: end of block | 0 | ||||||||||||
| 535 | m_separators += separator; | - | ||||||||||||
| 536 | } never executed: end of block | 0 | ||||||||||||
| 537 | - | |||||||||||||
| 538 | void QCalendarDateValidator::applyToDate() | - | ||||||||||||
| 539 | { | - | ||||||||||||
| 540 | m_currentDate = m_yearValidator.applyToDate(m_currentDate); | - | ||||||||||||
| 541 | m_currentDate = m_monthValidator.applyToDate(m_currentDate); | - | ||||||||||||
| 542 | m_currentDate = m_dayValidator.applyToDate(m_currentDate); | - | ||||||||||||
| 543 | } | - | ||||||||||||
| 544 | - | |||||||||||||
| 545 | void QCalendarDateValidator::toNextToken() | - | ||||||||||||
| 546 | { | - | ||||||||||||
| 547 | const int idx = m_tokens.indexOf(m_currentToken);if (idx == -1m_currentToken < 0
| 0 | ||||||||||||
| 548 | return; never executed: return; | 0 | ||||||||||||
| 549 | if (idx + 1 >= m_tokens.count())++m_currentToken= m_tokens.first(); | - | ||||||||||||
| else; | ||||||||||||||
| 550 | m_currentToken %= m_tokens.at(idx + 1);size(); | - | ||||||||||||
| 551 | } never executed: end of block | 0 | ||||||||||||
| 552 | - | |||||||||||||
| 553 | void QCalendarDateValidator::toPreviousToken() | - | ||||||||||||
| 554 | { | - | ||||||||||||
| 555 | const int idx = m_tokens.indexOf(m_currentToken); | 0 | ||||||||||||
| if (idx == -1) | ||||||||||||||
return;if (idx - 1m_currentToken
| ||||||||||||||
| 556 | return; never executed: return; | 0 | ||||||||||||
| 557 | --m_currentToken= m_tokens.last(); | - | ||||||||||||
| else; | ||||||||||||||
| 558 | m_currentToken %= m_tokens.at(idx - 1);size(); | - | ||||||||||||
| 559 | } never executed: end of block | 0 | ||||||||||||
| 560 | - | |||||||||||||
| 561 | void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent) | - | ||||||||||||
| 562 | { | - | ||||||||||||
| 563 | if (!(m_currentToken < 0
| 0 | ||||||||||||
| 564 | return; never executed: return; | 0 | ||||||||||||
| 565 | - | |||||||||||||
| 566 | int key = keyEvent->key(); | - | ||||||||||||
| 567 | if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection
| 0 | ||||||||||||
| 568 | if (key == Qt::Key_Back
| 0 | ||||||||||||
| 569 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||
| 570 | } never executed: end of block | 0 | ||||||||||||
| 571 | if (key == Qt::Key_Right
| 0 | ||||||||||||
| 572 | toNextToken(); never executed: toNextToken(); | 0 | ||||||||||||
| 573 | else if (key == Qt::Key_Left
| 0 | ||||||||||||
| 574 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||
| 575 | - | |||||||||||||
| 576 | m_lastSectionMove = m_tokens[m_currentToken->].validator->handleKey(key); | - | ||||||||||||
| 577 | - | |||||||||||||
| 578 | applyToDate(); | - | ||||||||||||
| 579 | if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection
| 0 | ||||||||||||
| 580 | toNextToken(); never executed: toNextToken(); | 0 | ||||||||||||
| 581 | else if (m_lastSectionMove == QCalendarDateSectionValidator::PrevSection
| 0 | ||||||||||||
| 582 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||
| 583 | } never executed: end of block | 0 | ||||||||||||
| 584 | - | |||||||||||||
| 585 | - | |||||||||||||
| 586 | - | |||||||||||||
| 587 | class QCalendarTextNavigator: public QObject | - | ||||||||||||
| 588 | { | - | ||||||||||||
| 589 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 590 | #pragma GCC diagnostic push | - | ||||||||||||
| 591 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 592 | #pragma GCC diagnostic pop | - | ||||||||||||
| 593 | struct QPrivateSignal {}; | - | ||||||||||||
| 594 | public: | - | ||||||||||||
| 595 | QCalendarTextNavigator(QObject *parent = 0) | - | ||||||||||||
| 596 | : QObject(parent), m_dateText(0), m_dateFrame(0), m_dateValidator(0), m_widget(0), m_editDelay(1500), m_date(QDate::currentDate()) { } | - | ||||||||||||
| 597 | - | |||||||||||||
| 598 | QWidget *widget() const; | - | ||||||||||||
| 599 | void setWidget(QWidget *widget); | - | ||||||||||||
| 600 | - | |||||||||||||
| 601 | int dateEditAcceptDelay() const; | - | ||||||||||||
| 602 | void setDateEditAcceptDelay(int delay); | - | ||||||||||||
| 603 | - | |||||||||||||
| 604 | void setDate(const QDate &date); | - | ||||||||||||
| 605 | - | |||||||||||||
| 606 | bool eventFilter(QObject *o, QEvent *e) override; | - | ||||||||||||
| 607 | void timerEvent(QTimerEvent *e) override; | - | ||||||||||||
| 608 | - | |||||||||||||
| 609 | public : | - | ||||||||||||
| 610 | void dateChanged(const QDate &date); | - | ||||||||||||
| 611 | void editingFinished(); | - | ||||||||||||
| 612 | - | |||||||||||||
| 613 | private: | - | ||||||||||||
| 614 | void applyDate(); | - | ||||||||||||
| 615 | void updateDateLabel(); | - | ||||||||||||
| 616 | void createDateLabel(); | - | ||||||||||||
| 617 | void removeDateLabel(); | - | ||||||||||||
| 618 | - | |||||||||||||
| 619 | QLabel *m_dateText; | - | ||||||||||||
| 620 | QFrame *m_dateFrame; | - | ||||||||||||
| 621 | QBasicTimer m_acceptTimer; | - | ||||||||||||
| 622 | QCalendarDateValidator *m_dateValidator; | - | ||||||||||||
| 623 | QWidget *m_widget; | - | ||||||||||||
| 624 | int m_editDelay; | - | ||||||||||||
| 625 | - | |||||||||||||
| 626 | QDate m_date; | - | ||||||||||||
| 627 | }; | - | ||||||||||||
| 628 | - | |||||||||||||
| 629 | QWidget *QCalendarTextNavigator::widget() const | - | ||||||||||||
| 630 | { | - | ||||||||||||
| 631 | return m_widget; | - | ||||||||||||
| 632 | } | - | ||||||||||||
| 633 | - | |||||||||||||
| 634 | void QCalendarTextNavigator::setWidget(QWidget *widget) | - | ||||||||||||
| 635 | { | - | ||||||||||||
| 636 | m_widget = widget; | - | ||||||||||||
| 637 | } | - | ||||||||||||
| 638 | - | |||||||||||||
| 639 | void QCalendarTextNavigator::setDate(const QDate &date) | - | ||||||||||||
| 640 | { | - | ||||||||||||
| 641 | m_date = date; | - | ||||||||||||
| 642 | } | - | ||||||||||||
| 643 | - | |||||||||||||
| 644 | void QCalendarTextNavigator::updateDateLabel() | - | ||||||||||||
| 645 | { | - | ||||||||||||
| 646 | if (!m_widget) | - | ||||||||||||
| 647 | return; | - | ||||||||||||
| 648 | - | |||||||||||||
| 649 | m_acceptTimer.start(m_editDelay, this); | - | ||||||||||||
| 650 | - | |||||||||||||
| 651 | m_dateText->setText(m_dateValidator->currentText()); | - | ||||||||||||
| 652 | - | |||||||||||||
| 653 | QSize s = m_dateFrame->sizeHint(); | - | ||||||||||||
| 654 | QRect r = m_widget->geometry(); | - | ||||||||||||
| 655 | QRect newRect((r.width() - s.width()) / 2, (r.height() - s.height()) / 2, s.width(), s.height()); | - | ||||||||||||
| 656 | m_dateFrame->setGeometry(newRect); | - | ||||||||||||
| 657 | - | |||||||||||||
| 658 | - | |||||||||||||
| 659 | QPalette p = m_dateFrame->palette(); | - | ||||||||||||
| 660 | p.setBrush(QPalette::Window, m_dateFrame->window()->palette().brush(QPalette::Window)); | - | ||||||||||||
| 661 | m_dateFrame->setPalette(p); | - | ||||||||||||
| 662 | - | |||||||||||||
| 663 | m_dateFrame->raise(); | - | ||||||||||||
| 664 | m_dateFrame->show(); | - | ||||||||||||
| 665 | } | - | ||||||||||||
| 666 | - | |||||||||||||
| 667 | void QCalendarTextNavigator::applyDate() | - | ||||||||||||
| 668 | { | - | ||||||||||||
| 669 | QDate date = m_dateValidator->currentDate(); | - | ||||||||||||
| 670 | if (m_date == date) | - | ||||||||||||
| 671 | return; | - | ||||||||||||
| 672 | - | |||||||||||||
| 673 | m_date = date; | - | ||||||||||||
| 674 | dateChanged(date); | - | ||||||||||||
| 675 | } | - | ||||||||||||
| 676 | - | |||||||||||||
| 677 | void QCalendarTextNavigator::createDateLabel() | - | ||||||||||||
| 678 | { | - | ||||||||||||
| 679 | if (m_dateFrame) | - | ||||||||||||
| 680 | return; | - | ||||||||||||
| 681 | m_dateFrame = new QFrame(m_widget); | - | ||||||||||||
| 682 | QVBoxLayout *vl = new QVBoxLayout; | - | ||||||||||||
| 683 | m_dateText = new QLabel; | - | ||||||||||||
| 684 | vl->addWidget(m_dateText); | - | ||||||||||||
| 685 | m_dateFrame->setLayout(vl); | - | ||||||||||||
| 686 | m_dateFrame->setFrameShadow(QFrame::Plain); | - | ||||||||||||
| 687 | m_dateFrame->setFrameShape(QFrame::Box); | - | ||||||||||||
| 688 | m_dateValidator = new QCalendarDateValidator(); | - | ||||||||||||
| 689 | m_dateValidator->setLocale(m_widget->locale()); | - | ||||||||||||
| 690 | m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat)); | - | ||||||||||||
| 691 | m_dateValidator->setInitialDate(m_date); | - | ||||||||||||
| 692 | - | |||||||||||||
| 693 | m_dateFrame->setAutoFillBackground(true); | - | ||||||||||||
| 694 | m_dateFrame->setBackgroundRole(QPalette::Window); | - | ||||||||||||
| 695 | } | - | ||||||||||||
| 696 | - | |||||||||||||
| 697 | void QCalendarTextNavigator::removeDateLabel() | - | ||||||||||||
| 698 | { | - | ||||||||||||
| 699 | if (!m_dateFrame) | - | ||||||||||||
| 700 | return; | - | ||||||||||||
| 701 | m_acceptTimer.stop(); | - | ||||||||||||
| 702 | m_dateFrame->hide(); | - | ||||||||||||
| 703 | m_dateFrame->deleteLater(); | - | ||||||||||||
| 704 | delete m_dateValidator; | - | ||||||||||||
| 705 | m_dateFrame = 0; | - | ||||||||||||
| 706 | m_dateText = 0; | - | ||||||||||||
| 707 | m_dateValidator = 0; | - | ||||||||||||
| 708 | } | - | ||||||||||||
| 709 | - | |||||||||||||
| 710 | bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||
| 711 | { | - | ||||||||||||
| 712 | if (m_widget) { | - | ||||||||||||
| 713 | if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) { | - | ||||||||||||
| 714 | QKeyEvent* ke = (QKeyEvent*)e; | - | ||||||||||||
| 715 | if ((ke->text().length() > 0 && ke->text()[0].isPrint()) || m_dateFrame) { | - | ||||||||||||
| 716 | if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Select) { | - | ||||||||||||
| 717 | applyDate(); | - | ||||||||||||
| 718 | editingFinished(); | - | ||||||||||||
| 719 | removeDateLabel(); | - | ||||||||||||
| 720 | } else if (ke->matches(QKeySequence::Cancel)) { | - | ||||||||||||
| 721 | removeDateLabel(); | - | ||||||||||||
| 722 | } else if (e->type() == QEvent::KeyPress) { | - | ||||||||||||
| 723 | createDateLabel(); | - | ||||||||||||
| 724 | m_dateValidator->handleKeyEvent(ke); | - | ||||||||||||
| 725 | updateDateLabel(); | - | ||||||||||||
| 726 | } | - | ||||||||||||
| 727 | ke->accept(); | - | ||||||||||||
| 728 | return true; | - | ||||||||||||
| 729 | } | - | ||||||||||||
| 730 | } | - | ||||||||||||
| 731 | } | - | ||||||||||||
| 732 | return QObject::eventFilter(o,e); | - | ||||||||||||
| 733 | } | - | ||||||||||||
| 734 | - | |||||||||||||
| 735 | void QCalendarTextNavigator::timerEvent(QTimerEvent *e) | - | ||||||||||||
| 736 | { | - | ||||||||||||
| 737 | if (e->timerId() == m_acceptTimer.timerId()) { | - | ||||||||||||
| 738 | applyDate(); | - | ||||||||||||
| 739 | removeDateLabel(); | - | ||||||||||||
| 740 | } | - | ||||||||||||
| 741 | } | - | ||||||||||||
| 742 | - | |||||||||||||
| 743 | int QCalendarTextNavigator::dateEditAcceptDelay() const | - | ||||||||||||
| 744 | { | - | ||||||||||||
| 745 | return m_editDelay; | - | ||||||||||||
| 746 | } | - | ||||||||||||
| 747 | - | |||||||||||||
| 748 | void QCalendarTextNavigator::setDateEditAcceptDelay(int delay) | - | ||||||||||||
| 749 | { | - | ||||||||||||
| 750 | m_editDelay = delay; | - | ||||||||||||
| 751 | } | - | ||||||||||||
| 752 | - | |||||||||||||
| 753 | class QCalendarView; | - | ||||||||||||
| 754 | - | |||||||||||||
| 755 | - | |||||||||||||
| 756 | - | |||||||||||||
| 757 | - | |||||||||||||
| 758 | - | |||||||||||||
| 759 | - | |||||||||||||
| 760 | #pragma GCC diagnostic push | - | ||||||||||||
| 761 | - | |||||||||||||
| 762 | - | |||||||||||||
| 763 | - | |||||||||||||
| 764 | template <typename T> | - | ||||||||||||
| 765 | class StaticDayOfWeekAssociativeArray { | - | ||||||||||||
| 766 | bool contained[7]; | - | ||||||||||||
| 767 | T data[7]; | - | ||||||||||||
| 768 | - | |||||||||||||
| 769 | static constexpr int day2idx(Qt::DayOfWeek day) noexcept { return int(day) - 1; } | - | ||||||||||||
| 770 | public: | - | ||||||||||||
| 771 | constexpr StaticDayOfWeekAssociativeArray() noexcept(noexcept(T())) | - | ||||||||||||
| 772 | : contained(), data() {} | - | ||||||||||||
| 773 | - | |||||||||||||
| 774 | constexpr bool contains(Qt::DayOfWeek day) const noexcept { return contained[day2idx(day)]; } | - | ||||||||||||
| 775 | constexpr const T &value(Qt::DayOfWeek day) const noexcept { return data[day2idx(day)]; } | - | ||||||||||||
| 776 | - | |||||||||||||
| 777 | T &operator[](Qt::DayOfWeek day) noexcept | - | ||||||||||||
| 778 | { | - | ||||||||||||
| 779 | const int idx = day2idx(day); | - | ||||||||||||
| 780 | contained[idx] = true; | - | ||||||||||||
| 781 | return never executed: return data[idx];never executed: data[idx];return data[idx];never executed: return data[idx]; | 0 | ||||||||||||
| 782 | } | - | ||||||||||||
| 783 | - | |||||||||||||
| 784 | void insert(Qt::DayOfWeek day, T v) noexcept | - | ||||||||||||
| 785 | { | - | ||||||||||||
| 786 | operator[](day).swap(v); | - | ||||||||||||
| 787 | } never executed: end of block | 0 | ||||||||||||
| 788 | }; | - | ||||||||||||
| 789 | - | |||||||||||||
| 790 | - | |||||||||||||
| 791 | #pragma GCC diagnostic pop | - | ||||||||||||
| 792 | - | |||||||||||||
| 793 | - | |||||||||||||
| 794 | class QCalendarModel : public QAbstractTableModel | - | ||||||||||||
| 795 | { | - | ||||||||||||
| 796 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 797 | #pragma GCC diagnostic push | - | ||||||||||||
| 798 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 799 | #pragma GCC diagnostic pop | - | ||||||||||||
| 800 | struct QPrivateSignal {}; | - | ||||||||||||
| 801 | public: | - | ||||||||||||
| 802 | QCalendarModel(QObject *parent = 0); | - | ||||||||||||
| 803 | - | |||||||||||||
| 804 | int rowCount(const QModelIndex &) const override | - | ||||||||||||
| 805 | { return RowCount + m_firstRow; } | - | ||||||||||||
| 806 | int columnCount(const QModelIndex &) const override | - | ||||||||||||
| 807 | { return ColumnCount + m_firstColumn; } | - | ||||||||||||
| 808 | QVariant data(const QModelIndex &index, int role) const override; | - | ||||||||||||
| 809 | Qt::ItemFlags flags(const QModelIndex &index) const override; | - | ||||||||||||
| 810 | - | |||||||||||||
| 811 | bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override | - | ||||||||||||
| 812 | { | - | ||||||||||||
| 813 | beginInsertRows(parent, row, row + count - 1); | - | ||||||||||||
| 814 | endInsertRows(); | - | ||||||||||||
| 815 | return true; | - | ||||||||||||
| 816 | } | - | ||||||||||||
| 817 | bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override | - | ||||||||||||
| 818 | { | - | ||||||||||||
| 819 | beginInsertColumns(parent, column, column + count - 1); | - | ||||||||||||
| 820 | endInsertColumns(); | - | ||||||||||||
| 821 | return true; | - | ||||||||||||
| 822 | } | - | ||||||||||||
| 823 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override | - | ||||||||||||
| 824 | { | - | ||||||||||||
| 825 | beginRemoveRows(parent, row, row + count - 1); | - | ||||||||||||
| 826 | endRemoveRows(); | - | ||||||||||||
| 827 | return true; | - | ||||||||||||
| 828 | } | - | ||||||||||||
| 829 | bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override | - | ||||||||||||
| 830 | { | - | ||||||||||||
| 831 | beginRemoveColumns(parent, column, column + count - 1); | - | ||||||||||||
| 832 | endRemoveColumns(); | - | ||||||||||||
| 833 | return true; | - | ||||||||||||
| 834 | } | - | ||||||||||||
| 835 | - | |||||||||||||
| 836 | void showMonth(int year, int month); | - | ||||||||||||
| 837 | void setDate(const QDate &d); | - | ||||||||||||
| 838 | - | |||||||||||||
| 839 | void setMinimumDate(const QDate &date); | - | ||||||||||||
| 840 | void setMaximumDate(const QDate &date); | - | ||||||||||||
| 841 | - | |||||||||||||
| 842 | void setRange(const QDate &min, const QDate &max); | - | ||||||||||||
| 843 | - | |||||||||||||
| 844 | void setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format); | - | ||||||||||||
| 845 | - | |||||||||||||
| 846 | void setFirstColumnDay(Qt::DayOfWeek dayOfWeek); | - | ||||||||||||
| 847 | Qt::DayOfWeek firstColumnDay() const; | - | ||||||||||||
| 848 | - | |||||||||||||
| 849 | bool weekNumbersShown() const; | - | ||||||||||||
| 850 | void setWeekNumbersShown(bool show); | - | ||||||||||||
| 851 | - | |||||||||||||
| 852 | QTextCharFormat formatForCell(int row, int col) const; | - | ||||||||||||
| 853 | Qt::DayOfWeek dayOfWeekForColumn(int section) const; | - | ||||||||||||
| 854 | int columnForDayOfWeek(Qt::DayOfWeek day) const; | - | ||||||||||||
| 855 | QDate dateForCell(int row, int column) const; | - | ||||||||||||
| 856 | void cellForDate(const QDate &date, int *row, int *column) const; | - | ||||||||||||
| 857 | QString dayName(Qt::DayOfWeek day) const; | - | ||||||||||||
| 858 | - | |||||||||||||
| 859 | void setView(QCalendarView *view) | - | ||||||||||||
| 860 | { m_view = view; } | - | ||||||||||||
| 861 | - | |||||||||||||
| 862 | void internalUpdate(); | - | ||||||||||||
| 863 | QDate referenceDate() const; | - | ||||||||||||
| 864 | int columnForFirstOfMonth(const QDate &date) const; | - | ||||||||||||
| 865 | - | |||||||||||||
| 866 | int m_firstColumn; | - | ||||||||||||
| 867 | int m_firstRow; | - | ||||||||||||
| 868 | QDate m_date; | - | ||||||||||||
| 869 | QDate m_minimumDate; | - | ||||||||||||
| 870 | QDate m_maximumDate; | - | ||||||||||||
| 871 | int m_shownYear; | - | ||||||||||||
| 872 | int m_shownMonth; | - | ||||||||||||
| 873 | Qt::DayOfWeek m_firstDay; | - | ||||||||||||
| 874 | QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat; | - | ||||||||||||
| 875 | bool m_weekNumbersShown; | - | ||||||||||||
| 876 | QMapStaticDayOfWeekAssociativeArray<Qt::DayOfWeek,QTextCharFormat> m_dayFormats; | - | ||||||||||||
| 877 | QMap<QDate, QTextCharFormat> m_dateFormats; | - | ||||||||||||
| 878 | QTextCharFormat m_headerFormat; | - | ||||||||||||
| 879 | QCalendarView *m_view; | - | ||||||||||||
| 880 | }; | - | ||||||||||||
| 881 | - | |||||||||||||
| 882 | class QCalendarView : public QTableView | - | ||||||||||||
| 883 | { | - | ||||||||||||
| 884 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 885 | #pragma GCC diagnostic push | - | ||||||||||||
| 886 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 887 | #pragma GCC diagnostic pop | - | ||||||||||||
| 888 | struct QPrivateSignal {}; | - | ||||||||||||
| 889 | public: | - | ||||||||||||
| 890 | QCalendarView(QWidget *parent = 0); | - | ||||||||||||
| 891 | - | |||||||||||||
| 892 | void internalUpdate() { updateGeometries(); } | - | ||||||||||||
| 893 | void setReadOnly(bool enable); | - | ||||||||||||
| 894 | virtual void keyboardSearch(const QString & search) override { (void)search; } | - | ||||||||||||
| 895 | - | |||||||||||||
| 896 | public : | - | ||||||||||||
| 897 | void showDate(const QDate &date); | - | ||||||||||||
| 898 | void changeDate(const QDate &date, bool changeMonth); | - | ||||||||||||
| 899 | void clicked(const QDate &date); | - | ||||||||||||
| 900 | void editingFinished(); | - | ||||||||||||
| 901 | protected: | - | ||||||||||||
| 902 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; | - | ||||||||||||
| 903 | void mouseDoubleClickEvent(QMouseEvent *event) override; | - | ||||||||||||
| 904 | void mousePressEvent(QMouseEvent *event) override; | - | ||||||||||||
| 905 | void mouseMoveEvent(QMouseEvent *event) override; | - | ||||||||||||
| 906 | void mouseReleaseEvent(QMouseEvent *event) override; | - | ||||||||||||
| 907 | - | |||||||||||||
| 908 | void wheelEvent(QWheelEvent *event) override; | - | ||||||||||||
| 909 | - | |||||||||||||
| 910 | void keyPressEvent(QKeyEvent *event) override; | - | ||||||||||||
| 911 | bool event(QEvent *event) override; | - | ||||||||||||
| 912 | - | |||||||||||||
| 913 | QDate handleMouseEvent(QMouseEvent *event); | - | ||||||||||||
| 914 | public: | - | ||||||||||||
| 915 | bool readOnly; | - | ||||||||||||
| 916 | private: | - | ||||||||||||
| 917 | bool validDateClicked; | - | ||||||||||||
| 918 | - | |||||||||||||
| 919 | - | |||||||||||||
| 920 | - | |||||||||||||
| 921 | }; | - | ||||||||||||
| 922 | - | |||||||||||||
| 923 | QCalendarModel::QCalendarModel(QObject *parent) | - | ||||||||||||
| 924 | : QAbstractTableModel(parent), | - | ||||||||||||
| 925 | m_firstColumn(1), | - | ||||||||||||
| 926 | m_firstRow(1), | - | ||||||||||||
| 927 | m_date(QDate::currentDate()), | - | ||||||||||||
| 928 | m_minimumDate(QDate::fromJulianDay(1)), | - | ||||||||||||
| 929 | m_maximumDate(7999, 12, 31), | - | ||||||||||||
| 930 | m_shownYear(m_date.year()), | - | ||||||||||||
| 931 | m_shownMonth(m_date.month()), | - | ||||||||||||
| 932 | m_firstDay(QLocale().firstDayOfWeek()), | - | ||||||||||||
| 933 | m_horizontalHeaderFormat(QCalendarWidget::ShortDayNames), | - | ||||||||||||
| 934 | m_weekNumbersShown(true), | - | ||||||||||||
| 935 | m_view(nullptr) | - | ||||||||||||
| 936 | { | - | ||||||||||||
| 937 | } | - | ||||||||||||
| 938 | - | |||||||||||||
| 939 | Qt::DayOfWeek QCalendarModel::dayOfWeekForColumn(int column) const | - | ||||||||||||
| 940 | { | - | ||||||||||||
| 941 | int col = column - m_firstColumn; | - | ||||||||||||
| 942 | if (col < 0 || col > 6) | - | ||||||||||||
| 943 | return Qt::Sunday; | - | ||||||||||||
| 944 | int day = m_firstDay + col; | - | ||||||||||||
| 945 | if (day > 7) | - | ||||||||||||
| 946 | day -= 7; | - | ||||||||||||
| 947 | return Qt::DayOfWeek(day); | - | ||||||||||||
| 948 | } | - | ||||||||||||
| 949 | - | |||||||||||||
| 950 | int QCalendarModel::columnForDayOfWeek(Qt::DayOfWeek day) const | - | ||||||||||||
| 951 | { | - | ||||||||||||
| 952 | if (day < 1 || day > 7) | - | ||||||||||||
| 953 | return -1; | - | ||||||||||||
| 954 | int column = (int)day - (int)m_firstDay; | - | ||||||||||||
| 955 | if (column < 0) | - | ||||||||||||
| 956 | column += 7; | - | ||||||||||||
| 957 | return column + m_firstColumn; | - | ||||||||||||
| 958 | } | - | ||||||||||||
| 959 | QDate QCalendarModel::referenceDate() const | - | ||||||||||||
| 960 | { | - | ||||||||||||
| 961 | int refDay = 1; | - | ||||||||||||
| 962 | while (refDay <= 31) { | - | ||||||||||||
| 963 | QDate refDate(m_shownYear, m_shownMonth, refDay); | - | ||||||||||||
| 964 | if (refDate.isValid()) | - | ||||||||||||
| 965 | return refDate; | - | ||||||||||||
| 966 | refDay += 1; | - | ||||||||||||
| 967 | } | - | ||||||||||||
| 968 | return QDate(); | - | ||||||||||||
| 969 | } | - | ||||||||||||
| 970 | - | |||||||||||||
| 971 | int QCalendarModel::columnForFirstOfMonth(const QDate &date) const | - | ||||||||||||
| 972 | { | - | ||||||||||||
| 973 | return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7; | - | ||||||||||||
| 974 | } | - | ||||||||||||
| 975 | - | |||||||||||||
| 976 | QDate QCalendarModel::dateForCell(int row, int column) const | - | ||||||||||||
| 977 | { | - | ||||||||||||
| 978 | if (row < m_firstRow || row > m_firstRow + RowCount - 1 || | - | ||||||||||||
| 979 | column < m_firstColumn || column > m_firstColumn + ColumnCount - 1) | - | ||||||||||||
| 980 | return QDate(); | - | ||||||||||||
| 981 | const QDate refDate = referenceDate(); | - | ||||||||||||
| 982 | if (!refDate.isValid()) | - | ||||||||||||
| 983 | return QDate(); | - | ||||||||||||
| 984 | - | |||||||||||||
| 985 | const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); | - | ||||||||||||
| 986 | if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset) | - | ||||||||||||
| 987 | row -= 1; | - | ||||||||||||
| 988 | - | |||||||||||||
| 989 | const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1; | - | ||||||||||||
| 990 | return refDate.addDays(requestedDay); | - | ||||||||||||
| 991 | } | - | ||||||||||||
| 992 | - | |||||||||||||
| 993 | void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const | - | ||||||||||||
| 994 | { | - | ||||||||||||
| 995 | if (!row && !column) | - | ||||||||||||
| 996 | return; | - | ||||||||||||
| 997 | - | |||||||||||||
| 998 | if (row) | - | ||||||||||||
| 999 | *row = -1; | - | ||||||||||||
| 1000 | if (column) | - | ||||||||||||
| 1001 | *column = -1; | - | ||||||||||||
| 1002 | - | |||||||||||||
| 1003 | const QDate refDate = referenceDate(); | - | ||||||||||||
| 1004 | if (!refDate.isValid()) | - | ||||||||||||
| 1005 | return; | - | ||||||||||||
| 1006 | - | |||||||||||||
| 1007 | const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); | - | ||||||||||||
| 1008 | const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1; | - | ||||||||||||
| 1009 | - | |||||||||||||
| 1010 | int c = requestedPosition % 7; | - | ||||||||||||
| 1011 | int r = requestedPosition / 7; | - | ||||||||||||
| 1012 | if (c < 0) { | - | ||||||||||||
| 1013 | c += 7; | - | ||||||||||||
| 1014 | r -= 1; | - | ||||||||||||
| 1015 | } | - | ||||||||||||
| 1016 | - | |||||||||||||
| 1017 | if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset) | - | ||||||||||||
| 1018 | r += 1; | - | ||||||||||||
| 1019 | - | |||||||||||||
| 1020 | if (r < 0 || r > RowCount - 1 || c < 0 || c > ColumnCount - 1) | - | ||||||||||||
| 1021 | return; | - | ||||||||||||
| 1022 | - | |||||||||||||
| 1023 | if (row) | - | ||||||||||||
| 1024 | *row = r + m_firstRow; | - | ||||||||||||
| 1025 | if (column) | - | ||||||||||||
| 1026 | *column = c + m_firstColumn; | - | ||||||||||||
| 1027 | } | - | ||||||||||||
| 1028 | - | |||||||||||||
| 1029 | QString QCalendarModel::dayName(Qt::DayOfWeek day) const | - | ||||||||||||
| 1030 | { | - | ||||||||||||
| 1031 | switch (m_horizontalHeaderFormat) { | - | ||||||||||||
| 1032 | case QCalendarWidget::SingleLetterDayNames: { | - | ||||||||||||
| 1033 | QString standaloneDayName = m_view->locale().standaloneDayName(day, QLocale::NarrowFormat); | - | ||||||||||||
| 1034 | if (standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat)) | - | ||||||||||||
| 1035 | return standaloneDayName.left(1); | - | ||||||||||||
| 1036 | return standaloneDayName; | - | ||||||||||||
| 1037 | } | - | ||||||||||||
| 1038 | case QCalendarWidget::ShortDayNames: | - | ||||||||||||
| 1039 | return m_view->locale().dayName(day, QLocale::ShortFormat); | - | ||||||||||||
| 1040 | case QCalendarWidget::LongDayNames: | - | ||||||||||||
| 1041 | return m_view->locale().dayName(day, QLocale::LongFormat); | - | ||||||||||||
| 1042 | default: | - | ||||||||||||
| 1043 | break; | - | ||||||||||||
| 1044 | } | - | ||||||||||||
| 1045 | return QString(); | - | ||||||||||||
| 1046 | } | - | ||||||||||||
| 1047 | - | |||||||||||||
| 1048 | QTextCharFormat QCalendarModel::formatForCell(int row, int col) const | - | ||||||||||||
| 1049 | { | - | ||||||||||||
| 1050 | QPalette pal; | - | ||||||||||||
| 1051 | QPalette::ColorGroup cg = QPalette::Active; | - | ||||||||||||
| 1052 | if (m_view) { | - | ||||||||||||
| 1053 | pal = m_view->palette(); | - | ||||||||||||
| 1054 | if (!m_view->isEnabled()) | - | ||||||||||||
| 1055 | cg = QPalette::Disabled; | - | ||||||||||||
| 1056 | else if (!m_view->isActiveWindow()) | - | ||||||||||||
| 1057 | cg = QPalette::Inactive; | - | ||||||||||||
| 1058 | } | - | ||||||||||||
| 1059 | - | |||||||||||||
| 1060 | QTextCharFormat format; | - | ||||||||||||
| 1061 | format.setFont(m_view->font()); | - | ||||||||||||
| 1062 | bool header = (m_weekNumbersShown && col == HeaderColumn) | - | ||||||||||||
| 1063 | || (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow); | - | ||||||||||||
| 1064 | format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base)); | - | ||||||||||||
| 1065 | format.setForeground(pal.brush(cg, QPalette::Text)); | - | ||||||||||||
| 1066 | if (header) { | - | ||||||||||||
| 1067 | format.merge(m_headerFormat); | - | ||||||||||||
| 1068 | } | - | ||||||||||||
| 1069 | - | |||||||||||||
| 1070 | if (col >= m_firstColumn && col < m_firstColumn + ColumnCount) { | - | ||||||||||||
| 1071 | Qt::DayOfWeek dayOfWeek = dayOfWeekForColumn(col); | - | ||||||||||||
| 1072 | if (m_dayFormats.contains(dayOfWeek)) | - | ||||||||||||
| 1073 | format.merge(m_dayFormats.value(dayOfWeek)); | - | ||||||||||||
| 1074 | } | - | ||||||||||||
| 1075 | - | |||||||||||||
| 1076 | if (!header) { | - | ||||||||||||
| 1077 | QDate date = dateForCell(row, col); | - | ||||||||||||
| 1078 | format.merge(m_dateFormats.value(date)); | - | ||||||||||||
| 1079 | if(date < m_minimumDate || date > m_maximumDate) | - | ||||||||||||
| 1080 | format.setBackground(pal.brush(cg, QPalette::Window)); | - | ||||||||||||
| 1081 | if (m_shownMonth != date.month()) | - | ||||||||||||
| 1082 | format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text)); | - | ||||||||||||
| 1083 | } | - | ||||||||||||
| 1084 | return format; | - | ||||||||||||
| 1085 | } | - | ||||||||||||
| 1086 | - | |||||||||||||
| 1087 | QVariant QCalendarModel::data(const QModelIndex &index, int role) const | - | ||||||||||||
| 1088 | { | - | ||||||||||||
| 1089 | if (role == Qt::TextAlignmentRole) | - | ||||||||||||
| 1090 | return (int) Qt::AlignCenter; | - | ||||||||||||
| 1091 | - | |||||||||||||
| 1092 | int row = index.row(); | - | ||||||||||||
| 1093 | int column = index.column(); | - | ||||||||||||
| 1094 | - | |||||||||||||
| 1095 | if(role == Qt::DisplayRole) { | - | ||||||||||||
| 1096 | if (m_weekNumbersShown && column == HeaderColumn | - | ||||||||||||
| 1097 | && row >= m_firstRow && row < m_firstRow + RowCount) { | - | ||||||||||||
| 1098 | QDate date = dateForCell(row, columnForDayOfWeek(Qt::Monday)); | - | ||||||||||||
| 1099 | if (date.isValid()) | - | ||||||||||||
| 1100 | return date.weekNumber(); | - | ||||||||||||
| 1101 | } | - | ||||||||||||
| 1102 | if (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow | - | ||||||||||||
| 1103 | && column >= m_firstColumn && column < m_firstColumn + ColumnCount) | - | ||||||||||||
| 1104 | return dayName(dayOfWeekForColumn(column)); | - | ||||||||||||
| 1105 | QDate date = dateForCell(row, column); | - | ||||||||||||
| 1106 | if (date.isValid()) | - | ||||||||||||
| 1107 | return date.day(); | - | ||||||||||||
| 1108 | return QString(); | - | ||||||||||||
| 1109 | } | - | ||||||||||||
| 1110 | - | |||||||||||||
| 1111 | QTextCharFormat fmt = formatForCell(row, column); | - | ||||||||||||
| 1112 | if (role == Qt::BackgroundColorRole) | - | ||||||||||||
| 1113 | return fmt.background().color(); | - | ||||||||||||
| 1114 | if (role == Qt::TextColorRole) | - | ||||||||||||
| 1115 | return fmt.foreground().color(); | - | ||||||||||||
| 1116 | if (role == Qt::FontRole) | - | ||||||||||||
| 1117 | return fmt.font(); | - | ||||||||||||
| 1118 | if (role == Qt::ToolTipRole) | - | ||||||||||||
| 1119 | return fmt.toolTip(); | - | ||||||||||||
| 1120 | return QVariant(); | - | ||||||||||||
| 1121 | } | - | ||||||||||||
| 1122 | - | |||||||||||||
| 1123 | Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const | - | ||||||||||||
| 1124 | { | - | ||||||||||||
| 1125 | QDate date = dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1126 | if (!date.isValid()) | - | ||||||||||||
| 1127 | return QAbstractTableModel::flags(index); | - | ||||||||||||
| 1128 | if (date < m_minimumDate) | - | ||||||||||||
| 1129 | return 0; | - | ||||||||||||
| 1130 | if (date > m_maximumDate) | - | ||||||||||||
| 1131 | return 0; | - | ||||||||||||
| 1132 | return QAbstractTableModel::flags(index); | - | ||||||||||||
| 1133 | } | - | ||||||||||||
| 1134 | - | |||||||||||||
| 1135 | void QCalendarModel::setDate(const QDate &d) | - | ||||||||||||
| 1136 | { | - | ||||||||||||
| 1137 | m_date = d; | - | ||||||||||||
| 1138 | if (m_date < m_minimumDate) | - | ||||||||||||
| 1139 | m_date = m_minimumDate; | - | ||||||||||||
| 1140 | else if (m_date > m_maximumDate) | - | ||||||||||||
| 1141 | m_date = m_maximumDate; | - | ||||||||||||
| 1142 | } | - | ||||||||||||
| 1143 | - | |||||||||||||
| 1144 | void QCalendarModel::showMonth(int year, int month) | - | ||||||||||||
| 1145 | { | - | ||||||||||||
| 1146 | if (m_shownYear == year && m_shownMonth == month) | - | ||||||||||||
| 1147 | return; | - | ||||||||||||
| 1148 | - | |||||||||||||
| 1149 | m_shownYear = year; | - | ||||||||||||
| 1150 | m_shownMonth = month; | - | ||||||||||||
| 1151 | - | |||||||||||||
| 1152 | internalUpdate(); | - | ||||||||||||
| 1153 | } | - | ||||||||||||
| 1154 | - | |||||||||||||
| 1155 | void QCalendarModel::setMinimumDate(const QDate &d) | - | ||||||||||||
| 1156 | { | - | ||||||||||||
| 1157 | if (!d.isValid() || d == m_minimumDate) | - | ||||||||||||
| 1158 | return; | - | ||||||||||||
| 1159 | - | |||||||||||||
| 1160 | m_minimumDate = d; | - | ||||||||||||
| 1161 | if (m_maximumDate < m_minimumDate) | - | ||||||||||||
| 1162 | m_maximumDate = m_minimumDate; | - | ||||||||||||
| 1163 | if (m_date < m_minimumDate) | - | ||||||||||||
| 1164 | m_date = m_minimumDate; | - | ||||||||||||
| 1165 | internalUpdate(); | - | ||||||||||||
| 1166 | } | - | ||||||||||||
| 1167 | - | |||||||||||||
| 1168 | void QCalendarModel::setMaximumDate(const QDate &d) | - | ||||||||||||
| 1169 | { | - | ||||||||||||
| 1170 | if (!d.isValid() || d == m_maximumDate) | - | ||||||||||||
| 1171 | return; | - | ||||||||||||
| 1172 | - | |||||||||||||
| 1173 | m_maximumDate = d; | - | ||||||||||||
| 1174 | if (m_minimumDate > m_maximumDate) | - | ||||||||||||
| 1175 | m_minimumDate = m_maximumDate; | - | ||||||||||||
| 1176 | if (m_date > m_maximumDate) | - | ||||||||||||
| 1177 | m_date = m_maximumDate; | - | ||||||||||||
| 1178 | internalUpdate(); | - | ||||||||||||
| 1179 | } | - | ||||||||||||
| 1180 | - | |||||||||||||
| 1181 | void QCalendarModel::setRange(const QDate &min, const QDate &max) | - | ||||||||||||
| 1182 | { | - | ||||||||||||
| 1183 | m_minimumDate = min; | - | ||||||||||||
| 1184 | m_maximumDate = max; | - | ||||||||||||
| 1185 | if (m_minimumDate > m_maximumDate) | - | ||||||||||||
| 1186 | qSwap(m_minimumDate, m_maximumDate); | - | ||||||||||||
| 1187 | if (m_date < m_minimumDate) | - | ||||||||||||
| 1188 | m_date = m_minimumDate; | - | ||||||||||||
| 1189 | if (m_date > m_maximumDate) | - | ||||||||||||
| 1190 | m_date = m_maximumDate; | - | ||||||||||||
| 1191 | internalUpdate(); | - | ||||||||||||
| 1192 | } | - | ||||||||||||
| 1193 | - | |||||||||||||
| 1194 | void QCalendarModel::internalUpdate() | - | ||||||||||||
| 1195 | { | - | ||||||||||||
| 1196 | QModelIndex begin = index(0, 0); | - | ||||||||||||
| 1197 | QModelIndex end = index(m_firstRow + RowCount - 1, m_firstColumn + ColumnCount - 1); | - | ||||||||||||
| 1198 | dataChanged(begin, end); | - | ||||||||||||
| 1199 | headerDataChanged(Qt::Vertical, 0, m_firstRow + RowCount - 1); | - | ||||||||||||
| 1200 | headerDataChanged(Qt::Horizontal, 0, m_firstColumn + ColumnCount - 1); | - | ||||||||||||
| 1201 | } | - | ||||||||||||
| 1202 | - | |||||||||||||
| 1203 | void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) | - | ||||||||||||
| 1204 | { | - | ||||||||||||
| 1205 | if (m_horizontalHeaderFormat == format) | - | ||||||||||||
| 1206 | return; | - | ||||||||||||
| 1207 | - | |||||||||||||
| 1208 | int oldFormat = m_horizontalHeaderFormat; | - | ||||||||||||
| 1209 | m_horizontalHeaderFormat = format; | - | ||||||||||||
| 1210 | if (oldFormat == QCalendarWidget::NoHorizontalHeader) { | - | ||||||||||||
| 1211 | m_firstRow = 1; | - | ||||||||||||
| 1212 | insertRow(0); | - | ||||||||||||
| 1213 | } else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) { | - | ||||||||||||
| 1214 | m_firstRow = 0; | - | ||||||||||||
| 1215 | removeRow(0); | - | ||||||||||||
| 1216 | } | - | ||||||||||||
| 1217 | internalUpdate(); | - | ||||||||||||
| 1218 | } | - | ||||||||||||
| 1219 | - | |||||||||||||
| 1220 | void QCalendarModel::setFirstColumnDay(Qt::DayOfWeek dayOfWeek) | - | ||||||||||||
| 1221 | { | - | ||||||||||||
| 1222 | if (m_firstDay == dayOfWeek) | - | ||||||||||||
| 1223 | return; | - | ||||||||||||
| 1224 | - | |||||||||||||
| 1225 | m_firstDay = dayOfWeek; | - | ||||||||||||
| 1226 | internalUpdate(); | - | ||||||||||||
| 1227 | } | - | ||||||||||||
| 1228 | - | |||||||||||||
| 1229 | Qt::DayOfWeek QCalendarModel::firstColumnDay() const | - | ||||||||||||
| 1230 | { | - | ||||||||||||
| 1231 | return m_firstDay; | - | ||||||||||||
| 1232 | } | - | ||||||||||||
| 1233 | - | |||||||||||||
| 1234 | bool QCalendarModel::weekNumbersShown() const | - | ||||||||||||
| 1235 | { | - | ||||||||||||
| 1236 | return m_weekNumbersShown; | - | ||||||||||||
| 1237 | } | - | ||||||||||||
| 1238 | - | |||||||||||||
| 1239 | void QCalendarModel::setWeekNumbersShown(bool show) | - | ||||||||||||
| 1240 | { | - | ||||||||||||
| 1241 | if (m_weekNumbersShown == show) | - | ||||||||||||
| 1242 | return; | - | ||||||||||||
| 1243 | - | |||||||||||||
| 1244 | m_weekNumbersShown = show; | - | ||||||||||||
| 1245 | if (show) { | - | ||||||||||||
| 1246 | m_firstColumn = 1; | - | ||||||||||||
| 1247 | insertColumn(0); | - | ||||||||||||
| 1248 | } else { | - | ||||||||||||
| 1249 | m_firstColumn = 0; | - | ||||||||||||
| 1250 | removeColumn(0); | - | ||||||||||||
| 1251 | } | - | ||||||||||||
| 1252 | internalUpdate(); | - | ||||||||||||
| 1253 | } | - | ||||||||||||
| 1254 | - | |||||||||||||
| 1255 | QCalendarView::QCalendarView(QWidget *parent) | - | ||||||||||||
| 1256 | : QTableView(parent), | - | ||||||||||||
| 1257 | readOnly(false), | - | ||||||||||||
| 1258 | validDateClicked(false) | - | ||||||||||||
| 1259 | { | - | ||||||||||||
| 1260 | setTabKeyNavigation(false); | - | ||||||||||||
| 1261 | setShowGrid(false); | - | ||||||||||||
| 1262 | verticalHeader()->setVisible(false); | - | ||||||||||||
| 1263 | horizontalHeader()->setVisible(false); | - | ||||||||||||
| 1264 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||
| 1265 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||
| 1266 | } | - | ||||||||||||
| 1267 | - | |||||||||||||
| 1268 | QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - | ||||||||||||
| 1269 | { | - | ||||||||||||
| 1270 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1271 | if (!calendarModel) | - | ||||||||||||
| 1272 | return QTableView::moveCursor(cursorAction, modifiers); | - | ||||||||||||
| 1273 | - | |||||||||||||
| 1274 | if (readOnly) | - | ||||||||||||
| 1275 | return currentIndex(); | - | ||||||||||||
| 1276 | - | |||||||||||||
| 1277 | QModelIndex index = currentIndex(); | - | ||||||||||||
| 1278 | QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1279 | switch (cursorAction) { | - | ||||||||||||
| 1280 | case QAbstractItemView::MoveUp: | - | ||||||||||||
| 1281 | currentDate = currentDate.addDays(-7); | - | ||||||||||||
| 1282 | break; | - | ||||||||||||
| 1283 | case QAbstractItemView::MoveDown: | - | ||||||||||||
| 1284 | currentDate = currentDate.addDays(7); | - | ||||||||||||
| 1285 | break; | - | ||||||||||||
| 1286 | case QAbstractItemView::MoveLeft: | - | ||||||||||||
| 1287 | currentDate = currentDate.addDays(isRightToLeft() ? 1 : -1); | - | ||||||||||||
| 1288 | break; | - | ||||||||||||
| 1289 | case QAbstractItemView::MoveRight: | - | ||||||||||||
| 1290 | currentDate = currentDate.addDays(isRightToLeft() ? -1 : 1); | - | ||||||||||||
| 1291 | break; | - | ||||||||||||
| 1292 | case QAbstractItemView::MoveHome: | - | ||||||||||||
| 1293 | currentDate = QDate(currentDate.year(), currentDate.month(), 1); | - | ||||||||||||
| 1294 | break; | - | ||||||||||||
| 1295 | case QAbstractItemView::MoveEnd: | - | ||||||||||||
| 1296 | currentDate = QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth()); | - | ||||||||||||
| 1297 | break; | - | ||||||||||||
| 1298 | case QAbstractItemView::MovePageUp: | - | ||||||||||||
| 1299 | currentDate = currentDate.addMonths(-1); | - | ||||||||||||
| 1300 | break; | - | ||||||||||||
| 1301 | case QAbstractItemView::MovePageDown: | - | ||||||||||||
| 1302 | currentDate = currentDate.addMonths(1); | - | ||||||||||||
| 1303 | break; | - | ||||||||||||
| 1304 | case QAbstractItemView::MoveNext: | - | ||||||||||||
| 1305 | case QAbstractItemView::MovePrevious: | - | ||||||||||||
| 1306 | return currentIndex(); | - | ||||||||||||
| 1307 | default: | - | ||||||||||||
| 1308 | break; | - | ||||||||||||
| 1309 | } | - | ||||||||||||
| 1310 | changeDate(currentDate, true); | - | ||||||||||||
| 1311 | return currentIndex(); | - | ||||||||||||
| 1312 | } | - | ||||||||||||
| 1313 | - | |||||||||||||
| 1314 | void QCalendarView::keyPressEvent(QKeyEvent *event) | - | ||||||||||||
| 1315 | { | - | ||||||||||||
| 1316 | if (!readOnly) { | - | ||||||||||||
| 1317 | switch (event->key()) { | - | ||||||||||||
| 1318 | case Qt::Key_Return: | - | ||||||||||||
| 1319 | case Qt::Key_Enter: | - | ||||||||||||
| 1320 | case Qt::Key_Select: | - | ||||||||||||
| 1321 | editingFinished(); | - | ||||||||||||
| 1322 | return; | - | ||||||||||||
| 1323 | default: | - | ||||||||||||
| 1324 | break; | - | ||||||||||||
| 1325 | } | - | ||||||||||||
| 1326 | } | - | ||||||||||||
| 1327 | QTableView::keyPressEvent(event); | - | ||||||||||||
| 1328 | } | - | ||||||||||||
| 1329 | - | |||||||||||||
| 1330 | - | |||||||||||||
| 1331 | void QCalendarView::wheelEvent(QWheelEvent *event) | - | ||||||||||||
| 1332 | { | - | ||||||||||||
| 1333 | const int numDegrees = event->delta() / 8; | - | ||||||||||||
| 1334 | const int numSteps = numDegrees / 15; | - | ||||||||||||
| 1335 | const QModelIndex index = currentIndex(); | - | ||||||||||||
| 1336 | QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1337 | currentDate = currentDate.addMonths(-numSteps); | - | ||||||||||||
| 1338 | showDate(currentDate); | - | ||||||||||||
| 1339 | } | - | ||||||||||||
| 1340 | - | |||||||||||||
| 1341 | - | |||||||||||||
| 1342 | bool QCalendarView::event(QEvent *event) | - | ||||||||||||
| 1343 | { | - | ||||||||||||
| 1344 | return QTableView::event(event); | - | ||||||||||||
| 1345 | } | - | ||||||||||||
| 1346 | - | |||||||||||||
| 1347 | QDate QCalendarView::handleMouseEvent(QMouseEvent *event) | - | ||||||||||||
| 1348 | { | - | ||||||||||||
| 1349 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1350 | if (!calendarModel) | - | ||||||||||||
| 1351 | return QDate(); | - | ||||||||||||
| 1352 | - | |||||||||||||
| 1353 | QPoint pos = event->pos(); | - | ||||||||||||
| 1354 | QModelIndex index = indexAt(pos); | - | ||||||||||||
| 1355 | QDate date = calendarModel->dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1356 | if (date.isValid() && date >= calendarModel->m_minimumDate | - | ||||||||||||
| 1357 | && date <= calendarModel->m_maximumDate) { | - | ||||||||||||
| 1358 | return date; | - | ||||||||||||
| 1359 | } | - | ||||||||||||
| 1360 | return QDate(); | - | ||||||||||||
| 1361 | } | - | ||||||||||||
| 1362 | - | |||||||||||||
| 1363 | void QCalendarView::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||
| 1364 | { | - | ||||||||||||
| 1365 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1366 | if (!calendarModel) { | - | ||||||||||||
| 1367 | QTableView::mouseDoubleClickEvent(event); | - | ||||||||||||
| 1368 | return; | - | ||||||||||||
| 1369 | } | - | ||||||||||||
| 1370 | - | |||||||||||||
| 1371 | if (readOnly) | - | ||||||||||||
| 1372 | return; | - | ||||||||||||
| 1373 | - | |||||||||||||
| 1374 | QDate date = handleMouseEvent(event); | - | ||||||||||||
| 1375 | validDateClicked = false; | - | ||||||||||||
| 1376 | if (date == calendarModel->m_date && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) { | - | ||||||||||||
| 1377 | editingFinished(); | - | ||||||||||||
| 1378 | } | - | ||||||||||||
| 1379 | } | - | ||||||||||||
| 1380 | - | |||||||||||||
| 1381 | void QCalendarView::mousePressEvent(QMouseEvent *event) | - | ||||||||||||
| 1382 | { | - | ||||||||||||
| 1383 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1384 | if (!calendarModel) { | - | ||||||||||||
| 1385 | QTableView::mousePressEvent(event); | - | ||||||||||||
| 1386 | return; | - | ||||||||||||
| 1387 | } | - | ||||||||||||
| 1388 | - | |||||||||||||
| 1389 | if (readOnly) | - | ||||||||||||
| 1390 | return; | - | ||||||||||||
| 1391 | - | |||||||||||||
| 1392 | if (event->button() != Qt::LeftButton) | - | ||||||||||||
| 1393 | return; | - | ||||||||||||
| 1394 | - | |||||||||||||
| 1395 | QDate date = handleMouseEvent(event); | - | ||||||||||||
| 1396 | if (date.isValid()) { | - | ||||||||||||
| 1397 | validDateClicked = true; | - | ||||||||||||
| 1398 | int row = -1, col = -1; | - | ||||||||||||
| 1399 | static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); | - | ||||||||||||
| 1400 | if (row != -1 && col != -1) { | - | ||||||||||||
| 1401 | selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); | - | ||||||||||||
| 1402 | } | - | ||||||||||||
| 1403 | } else { | - | ||||||||||||
| 1404 | validDateClicked = false; | - | ||||||||||||
| 1405 | event->ignore(); | - | ||||||||||||
| 1406 | } | - | ||||||||||||
| 1407 | } | - | ||||||||||||
| 1408 | - | |||||||||||||
| 1409 | void QCalendarView::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||
| 1410 | { | - | ||||||||||||
| 1411 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1412 | if (!calendarModel) { | - | ||||||||||||
| 1413 | QTableView::mouseMoveEvent(event); | - | ||||||||||||
| 1414 | return; | - | ||||||||||||
| 1415 | } | - | ||||||||||||
| 1416 | - | |||||||||||||
| 1417 | if (readOnly) | - | ||||||||||||
| 1418 | return; | - | ||||||||||||
| 1419 | - | |||||||||||||
| 1420 | if (validDateClicked) { | - | ||||||||||||
| 1421 | QDate date = handleMouseEvent(event); | - | ||||||||||||
| 1422 | if (date.isValid()) { | - | ||||||||||||
| 1423 | int row = -1, col = -1; | - | ||||||||||||
| 1424 | static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); | - | ||||||||||||
| 1425 | if (row != -1 && col != -1) { | - | ||||||||||||
| 1426 | selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); | - | ||||||||||||
| 1427 | } | - | ||||||||||||
| 1428 | } | - | ||||||||||||
| 1429 | } else { | - | ||||||||||||
| 1430 | event->ignore(); | - | ||||||||||||
| 1431 | } | - | ||||||||||||
| 1432 | } | - | ||||||||||||
| 1433 | - | |||||||||||||
| 1434 | void QCalendarView::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||
| 1435 | { | - | ||||||||||||
| 1436 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||
| 1437 | if (!calendarModel) { | - | ||||||||||||
| 1438 | QTableView::mouseReleaseEvent(event); | - | ||||||||||||
| 1439 | return; | - | ||||||||||||
| 1440 | } | - | ||||||||||||
| 1441 | - | |||||||||||||
| 1442 | if (event->button() != Qt::LeftButton) | - | ||||||||||||
| 1443 | return; | - | ||||||||||||
| 1444 | - | |||||||||||||
| 1445 | if (readOnly) | - | ||||||||||||
| 1446 | return; | - | ||||||||||||
| 1447 | - | |||||||||||||
| 1448 | if (validDateClicked) { | - | ||||||||||||
| 1449 | QDate date = handleMouseEvent(event); | - | ||||||||||||
| 1450 | if (date.isValid()) { | - | ||||||||||||
| 1451 | changeDate(date, true); | - | ||||||||||||
| 1452 | clicked(date); | - | ||||||||||||
| 1453 | if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) | - | ||||||||||||
| 1454 | editingFinished(); | - | ||||||||||||
| 1455 | } | - | ||||||||||||
| 1456 | validDateClicked = false; | - | ||||||||||||
| 1457 | } else { | - | ||||||||||||
| 1458 | event->ignore(); | - | ||||||||||||
| 1459 | } | - | ||||||||||||
| 1460 | } | - | ||||||||||||
| 1461 | - | |||||||||||||
| 1462 | class QCalendarDelegate : public QItemDelegate | - | ||||||||||||
| 1463 | { | - | ||||||||||||
| 1464 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 1465 | #pragma GCC diagnostic push | - | ||||||||||||
| 1466 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 1467 | #pragma GCC diagnostic pop | - | ||||||||||||
| 1468 | struct QPrivateSignal {}; | - | ||||||||||||
| 1469 | public: | - | ||||||||||||
| 1470 | QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = 0) | - | ||||||||||||
| 1471 | : QItemDelegate(parent), calendarWidgetPrivate(w) | - | ||||||||||||
| 1472 | { } | - | ||||||||||||
| 1473 | virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, | - | ||||||||||||
| 1474 | const QModelIndex &index) const override; | - | ||||||||||||
| 1475 | void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; | - | ||||||||||||
| 1476 | - | |||||||||||||
| 1477 | private: | - | ||||||||||||
| 1478 | QCalendarWidgetPrivate *calendarWidgetPrivate; | - | ||||||||||||
| 1479 | mutable QStyleOptionViewItem storedOption; | - | ||||||||||||
| 1480 | }; | - | ||||||||||||
| 1481 | - | |||||||||||||
| 1482 | - | |||||||||||||
| 1483 | class QCalToolButton: public QToolButton | - | ||||||||||||
| 1484 | { | - | ||||||||||||
| 1485 | public: | - | ||||||||||||
| 1486 | QCalToolButton(QWidget * parent) | - | ||||||||||||
| 1487 | : QToolButton(parent) | - | ||||||||||||
| 1488 | { } | - | ||||||||||||
| 1489 | protected: | - | ||||||||||||
| 1490 | void paintEvent(QPaintEvent *e) override | - | ||||||||||||
| 1491 | { | - | ||||||||||||
| 1492 | (void)e; | - | ||||||||||||
| 1493 | - | |||||||||||||
| 1494 | - | |||||||||||||
| 1495 | QStyleOptionToolButton opt; | - | ||||||||||||
| 1496 | initStyleOption(&opt); | - | ||||||||||||
| 1497 | - | |||||||||||||
| 1498 | if (opt.state & QStyle::State_MouseOver || isDown()) { | - | ||||||||||||
| 1499 | - | |||||||||||||
| 1500 | setPalette(QPalette()); | - | ||||||||||||
| 1501 | } else { | - | ||||||||||||
| 1502 | - | |||||||||||||
| 1503 | QPalette toolPalette = palette(); | - | ||||||||||||
| 1504 | toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText)); | - | ||||||||||||
| 1505 | setPalette(toolPalette); | - | ||||||||||||
| 1506 | } | - | ||||||||||||
| 1507 | - | |||||||||||||
| 1508 | QToolButton::paintEvent(e); | - | ||||||||||||
| 1509 | } | - | ||||||||||||
| 1510 | }; | - | ||||||||||||
| 1511 | - | |||||||||||||
| 1512 | class QPrevNextCalButton : public QToolButton | - | ||||||||||||
| 1513 | { | - | ||||||||||||
| 1514 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 1515 | #pragma GCC diagnostic push | - | ||||||||||||
| 1516 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 1517 | #pragma GCC diagnostic pop | - | ||||||||||||
| 1518 | struct QPrivateSignal {}; | - | ||||||||||||
| 1519 | public: | - | ||||||||||||
| 1520 | QPrevNextCalButton(QWidget *parent) : QToolButton(parent) {} | - | ||||||||||||
| 1521 | protected: | - | ||||||||||||
| 1522 | void paintEvent(QPaintEvent *) override { | - | ||||||||||||
| 1523 | QStylePainter painter(this); | - | ||||||||||||
| 1524 | QStyleOptionToolButton opt; | - | ||||||||||||
| 1525 | initStyleOption(&opt); | - | ||||||||||||
| 1526 | opt.state &= ~QStyle::State_HasFocus; | - | ||||||||||||
| 1527 | painter.drawComplexControl(QStyle::CC_ToolButton, opt); | - | ||||||||||||
| 1528 | } | - | ||||||||||||
| 1529 | }; | - | ||||||||||||
| 1530 | - | |||||||||||||
| 1531 | } | - | ||||||||||||
| 1532 | - | |||||||||||||
| 1533 | class QCalendarWidgetPrivate : public QWidgetPrivate | - | ||||||||||||
| 1534 | { | - | ||||||||||||
| 1535 | inline QCalendarWidget* q_func() { return static_cast<QCalendarWidget *>(q_ptr); } inline const QCalendarWidget* q_func() const { return static_cast<const QCalendarWidget *>(q_ptr); } friend class QCalendarWidget; | - | ||||||||||||
| 1536 | public: | - | ||||||||||||
| 1537 | QCalendarWidgetPrivate(); | - | ||||||||||||
| 1538 | - | |||||||||||||
| 1539 | void showMonth(int year, int month); | - | ||||||||||||
| 1540 | void update(); | - | ||||||||||||
| 1541 | void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; | - | ||||||||||||
| 1542 | - | |||||||||||||
| 1543 | void _q_slotShowDate(const QDate &date); | - | ||||||||||||
| 1544 | void _q_slotChangeDate(const QDate &date); | - | ||||||||||||
| 1545 | void _q_slotChangeDate(const QDate &date, bool changeMonth); | - | ||||||||||||
| 1546 | void _q_editingFinished(); | - | ||||||||||||
| 1547 | void _q_monthChanged(QAction*); | - | ||||||||||||
| 1548 | void _q_prevMonthClicked(); | - | ||||||||||||
| 1549 | void _q_nextMonthClicked(); | - | ||||||||||||
| 1550 | void _q_yearEditingFinished(); | - | ||||||||||||
| 1551 | void _q_yearClicked(); | - | ||||||||||||
| 1552 | - | |||||||||||||
| 1553 | void createNavigationBar(QWidget *widget); | - | ||||||||||||
| 1554 | void updateButtonIcons(); | - | ||||||||||||
| 1555 | void updateMonthMenu(); | - | ||||||||||||
| 1556 | void updateMonthMenuNames(); | - | ||||||||||||
| 1557 | void updateNavigationBar(); | - | ||||||||||||
| 1558 | void updateCurrentPage(const QDate &newDate); | - | ||||||||||||
| 1559 | inline QDate getCurrentDate(); | - | ||||||||||||
| 1560 | void setNavigatorEnabled(bool enable); | - | ||||||||||||
| 1561 | - | |||||||||||||
| 1562 | QCalendarModel *m_model; | - | ||||||||||||
| 1563 | QCalendarView *m_view; | - | ||||||||||||
| 1564 | QCalendarDelegate *m_delegate; | - | ||||||||||||
| 1565 | QItemSelectionModel *m_selection; | - | ||||||||||||
| 1566 | QCalendarTextNavigator *m_navigator; | - | ||||||||||||
| 1567 | bool m_dateEditEnabled; | - | ||||||||||||
| 1568 | - | |||||||||||||
| 1569 | QToolButton *nextMonth; | - | ||||||||||||
| 1570 | QToolButton *prevMonth; | - | ||||||||||||
| 1571 | QCalToolButton *monthButton; | - | ||||||||||||
| 1572 | QMenu *monthMenu; | - | ||||||||||||
| 1573 | QMap<int, QAction *> monthToAction; | - | ||||||||||||
| 1574 | QCalToolButton *yearButton; | - | ||||||||||||
| 1575 | QSpinBox *yearEdit; | - | ||||||||||||
| 1576 | QWidget *navBarBackground; | - | ||||||||||||
| 1577 | QSpacerItem *spaceHolder; | - | ||||||||||||
| 1578 | - | |||||||||||||
| 1579 | bool navBarVisible; | - | ||||||||||||
| 1580 | mutable QSize cachedSizeHint; | - | ||||||||||||
| 1581 | Qt::FocusPolicy oldFocusPolicy; | - | ||||||||||||
| 1582 | }; | - | ||||||||||||
| 1583 | - | |||||||||||||
| 1584 | void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, | - | ||||||||||||
| 1585 | const QModelIndex &index) const | - | ||||||||||||
| 1586 | { | - | ||||||||||||
| 1587 | QDate date = calendarWidgetPrivate->m_model->dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1588 | if (date.isValid()) { | - | ||||||||||||
| 1589 | storedOption = option; | - | ||||||||||||
| 1590 | QRect rect = option.rect; | - | ||||||||||||
| 1591 | calendarWidgetPrivate->paintCell(painter, rect, date); | - | ||||||||||||
| 1592 | } else { | - | ||||||||||||
| 1593 | QItemDelegate::paint(painter, option, index); | - | ||||||||||||
| 1594 | } | - | ||||||||||||
| 1595 | } | - | ||||||||||||
| 1596 | - | |||||||||||||
| 1597 | void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||
| 1598 | { | - | ||||||||||||
| 1599 | storedOption.rect = rect; | - | ||||||||||||
| 1600 | int row = -1; | - | ||||||||||||
| 1601 | int col = -1; | - | ||||||||||||
| 1602 | calendarWidgetPrivate->m_model->cellForDate(date, &row, &col); | - | ||||||||||||
| 1603 | QModelIndex idx = calendarWidgetPrivate->m_model->index(row, col); | - | ||||||||||||
| 1604 | QItemDelegate::paint(painter, storedOption, idx); | - | ||||||||||||
| 1605 | } | - | ||||||||||||
| 1606 | - | |||||||||||||
| 1607 | QCalendarWidgetPrivate::QCalendarWidgetPrivate() | - | ||||||||||||
| 1608 | : QWidgetPrivate() | - | ||||||||||||
| 1609 | { | - | ||||||||||||
| 1610 | m_model = 0; | - | ||||||||||||
| 1611 | m_view = 0; | - | ||||||||||||
| 1612 | m_delegate = 0; | - | ||||||||||||
| 1613 | m_selection = 0; | - | ||||||||||||
| 1614 | m_navigator = 0; | - | ||||||||||||
| 1615 | m_dateEditEnabled = false; | - | ||||||||||||
| 1616 | navBarVisible = true; | - | ||||||||||||
| 1617 | oldFocusPolicy = Qt::StrongFocus; | - | ||||||||||||
| 1618 | } | - | ||||||||||||
| 1619 | - | |||||||||||||
| 1620 | void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable) | - | ||||||||||||
| 1621 | { | - | ||||||||||||
| 1622 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1623 | - | |||||||||||||
| 1624 | bool navigatorEnabled = (m_navigator->widget() != 0); | - | ||||||||||||
| 1625 | if (enable == navigatorEnabled) | - | ||||||||||||
| 1626 | return; | - | ||||||||||||
| 1627 | - | |||||||||||||
| 1628 | if (enable) { | - | ||||||||||||
| 1629 | m_navigator->setWidget(q); | - | ||||||||||||
| 1630 | q->connect(m_navigator, qFlagLocation("2""dateChanged(QDate)" "\0" __FILE__ ":" "1677""1713"), | - | ||||||||||||
| 1631 | q, qFlagLocation("1""_q_slotChangeDate(QDate)" "\0" __FILE__ ":" "1678""1714")); | - | ||||||||||||
| 1632 | q->connect(m_navigator, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "1679""1715"), | - | ||||||||||||
| 1633 | q, qFlagLocation("1""_q_editingFinished()" "\0" __FILE__ ":" "1680""1716")); | - | ||||||||||||
| 1634 | m_view->installEventFilter(m_navigator); | - | ||||||||||||
| 1635 | } else { | - | ||||||||||||
| 1636 | m_navigator->setWidget(0); | - | ||||||||||||
| 1637 | q->disconnect(m_navigator, qFlagLocation("2""dateChanged(QDate)" "\0" __FILE__ ":" "1684""1720"), | - | ||||||||||||
| 1638 | q, qFlagLocation("1""_q_slotChangeDate(QDate)" "\0" __FILE__ ":" "1685""1721")); | - | ||||||||||||
| 1639 | q->disconnect(m_navigator, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "1686""1722"), | - | ||||||||||||
| 1640 | q, qFlagLocation("1""_q_editingFinished()" "\0" __FILE__ ":" "1687""1723")); | - | ||||||||||||
| 1641 | m_view->removeEventFilter(m_navigator); | - | ||||||||||||
| 1642 | } | - | ||||||||||||
| 1643 | } | - | ||||||||||||
| 1644 | - | |||||||||||||
| 1645 | void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) | - | ||||||||||||
| 1646 | { | - | ||||||||||||
| 1647 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1648 | navBarBackground = new QWidget(widget); | - | ||||||||||||
| 1649 | navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar")); | - | ||||||||||||
| 1650 | navBarBackground->setAutoFillBackground(true); | - | ||||||||||||
| 1651 | navBarBackground->setBackgroundRole(QPalette::Highlight); | - | ||||||||||||
| 1652 | - | |||||||||||||
| 1653 | prevMonth = new QPrevNextCalButton(navBarBackground); | - | ||||||||||||
| 1654 | nextMonth = new QPrevNextCalButton(navBarBackground); | - | ||||||||||||
| 1655 | prevMonth->setAutoRaise(true); | - | ||||||||||||
| 1656 | nextMonth->setAutoRaise(true); | - | ||||||||||||
| 1657 | prevMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||
| 1658 | nextMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||
| 1659 | nextMonth->setAutoRaise(true); | - | ||||||||||||
| 1660 | updateButtonIcons(); | - | ||||||||||||
| 1661 | prevMonth->setAutoRepeat(true); | - | ||||||||||||
| 1662 | nextMonth->setAutoRepeat(true); | - | ||||||||||||
| 1663 | - | |||||||||||||
| 1664 | monthButton = new QCalToolButton(navBarBackground); | - | ||||||||||||
| 1665 | monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||
| 1666 | monthButton->setAutoRaise(true); | - | ||||||||||||
| 1667 | monthButton->setPopupMode(QToolButton::InstantPopup); | - | ||||||||||||
| 1668 | monthMenu = new QMenu(monthButton); | - | ||||||||||||
| 1669 | for (int i = 1; i <= 12; i++) { | - | ||||||||||||
| 1670 | QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); | - | ||||||||||||
| 1671 | QAction *act = monthMenu->addAction(monthName); | - | ||||||||||||
| 1672 | act->setData(i); | - | ||||||||||||
| 1673 | monthToAction[i] = act; | - | ||||||||||||
| 1674 | } | - | ||||||||||||
| 1675 | monthButton->setMenu(monthMenu); | - | ||||||||||||
| 1676 | yearButton = new QCalToolButton(navBarBackground); | - | ||||||||||||
| 1677 | yearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||
| 1678 | yearButton->setAutoRaise(true); | - | ||||||||||||
| 1679 | yearEdit = new QSpinBox(navBarBackground); | - | ||||||||||||
| 1680 | - | |||||||||||||
| 1681 | QFont font = q->font(); | - | ||||||||||||
| 1682 | font.setBold(true); | - | ||||||||||||
| 1683 | monthButton->setFont(font); | - | ||||||||||||
| 1684 | yearButton->setFont(font); | - | ||||||||||||
| 1685 | yearEdit->setFrame(false); | - | ||||||||||||
| 1686 | yearEdit->setMinimum(m_model->m_minimumDate.year()); | - | ||||||||||||
| 1687 | yearEdit->setMaximum(m_model->m_maximumDate.year()); | - | ||||||||||||
| 1688 | yearEdit->hide(); | - | ||||||||||||
| 1689 | spaceHolder = new QSpacerItem(0,0); | - | ||||||||||||
| 1690 | - | |||||||||||||
| 1691 | QHBoxLayout *headerLayout = new QHBoxLayout; | - | ||||||||||||
| 1692 | headerLayout->setMargin(0); | - | ||||||||||||
| 1693 | headerLayout->setSpacing(0); | - | ||||||||||||
| 1694 | headerLayout->addWidget(prevMonth); | - | ||||||||||||
| 1695 | headerLayout->insertStretch(headerLayout->count()); | - | ||||||||||||
| 1696 | headerLayout->addWidget(monthButton); | - | ||||||||||||
| 1697 | headerLayout->addItem(spaceHolder); | - | ||||||||||||
| 1698 | headerLayout->addWidget(yearButton); | - | ||||||||||||
| 1699 | headerLayout->insertStretch(headerLayout->count()); | - | ||||||||||||
| 1700 | headerLayout->addWidget(nextMonth); | - | ||||||||||||
| 1701 | navBarBackground->setLayout(headerLayout); | - | ||||||||||||
| 1702 | - | |||||||||||||
| 1703 | yearEdit->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||
| 1704 | prevMonth->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 1705 | nextMonth->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 1706 | yearButton->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 1707 | monthButton->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 1708 | - | |||||||||||||
| 1709 | - | |||||||||||||
| 1710 | prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth")); | - | ||||||||||||
| 1711 | nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth")); | - | ||||||||||||
| 1712 | monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton")); | - | ||||||||||||
| 1713 | yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton")); | - | ||||||||||||
| 1714 | yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit")); | - | ||||||||||||
| 1715 | - | |||||||||||||
| 1716 | updateMonthMenu(); | - | ||||||||||||
| 1717 | showMonth(m_model->m_date.year(), m_model->m_date.month()); | - | ||||||||||||
| 1718 | } | - | ||||||||||||
| 1719 | - | |||||||||||||
| 1720 | void QCalendarWidgetPrivate::updateButtonIcons() | - | ||||||||||||
| 1721 | { | - | ||||||||||||
| 1722 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1723 | prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, 0, q)); | - | ||||||||||||
| 1724 | nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, 0, q)); | - | ||||||||||||
| 1725 | } | - | ||||||||||||
| 1726 | - | |||||||||||||
| 1727 | void QCalendarWidgetPrivate::updateMonthMenu() | - | ||||||||||||
| 1728 | { | - | ||||||||||||
| 1729 | int beg = 1, end = 12; | - | ||||||||||||
| 1730 | bool prevEnabled = true; | - | ||||||||||||
| 1731 | bool nextEnabled = true; | - | ||||||||||||
| 1732 | if (m_model->m_shownYear == m_model->m_minimumDate.year()) { | - | ||||||||||||
| 1733 | beg = m_model->m_minimumDate.month(); | - | ||||||||||||
| 1734 | if (m_model->m_shownMonth == m_model->m_minimumDate.month()) | - | ||||||||||||
| 1735 | prevEnabled = false; | - | ||||||||||||
| 1736 | } | - | ||||||||||||
| 1737 | if (m_model->m_shownYear == m_model->m_maximumDate.year()) { | - | ||||||||||||
| 1738 | end = m_model->m_maximumDate.month(); | - | ||||||||||||
| 1739 | if (m_model->m_shownMonth == m_model->m_maximumDate.month()) | - | ||||||||||||
| 1740 | nextEnabled = false; | - | ||||||||||||
| 1741 | } | - | ||||||||||||
| 1742 | prevMonth->setEnabled(prevEnabled); | - | ||||||||||||
| 1743 | nextMonth->setEnabled(nextEnabled); | - | ||||||||||||
| 1744 | for (int i = 1; i <= 12; i++) { | - | ||||||||||||
| 1745 | bool monthEnabled = true; | - | ||||||||||||
| 1746 | if (i < beg || i > end) | - | ||||||||||||
| 1747 | monthEnabled = false; | - | ||||||||||||
| 1748 | monthToAction[i]->setEnabled(monthEnabled); | - | ||||||||||||
| 1749 | } | - | ||||||||||||
| 1750 | } | - | ||||||||||||
| 1751 | - | |||||||||||||
| 1752 | void QCalendarWidgetPrivate::updateMonthMenuNames() | - | ||||||||||||
| 1753 | { | - | ||||||||||||
| 1754 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1755 | - | |||||||||||||
| 1756 | for (int i = 1; i <= 12; i++) { | - | ||||||||||||
| 1757 | QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); | - | ||||||||||||
| 1758 | monthToAction[i]->setText(monthName); | - | ||||||||||||
| 1759 | } | - | ||||||||||||
| 1760 | } | - | ||||||||||||
| 1761 | - | |||||||||||||
| 1762 | void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date) | - | ||||||||||||
| 1763 | { | - | ||||||||||||
| 1764 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1765 | - | |||||||||||||
| 1766 | QDate newDate = date; | - | ||||||||||||
| 1767 | QDate minDate = q->minimumDate(); | - | ||||||||||||
| 1768 | QDate maxDate = q->maximumDate(); | - | ||||||||||||
| 1769 | if (minDate.isValid()&& minDate.daysTo(newDate) < 0) | - | ||||||||||||
| 1770 | newDate = minDate; | - | ||||||||||||
| 1771 | if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0) | - | ||||||||||||
| 1772 | newDate = maxDate; | - | ||||||||||||
| 1773 | showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 1774 | int row = -1, col = -1; | - | ||||||||||||
| 1775 | m_model->cellForDate(newDate, &row, &col); | - | ||||||||||||
| 1776 | if (row != -1 && col != -1) | - | ||||||||||||
| 1777 | { | - | ||||||||||||
| 1778 | m_view->selectionModel()->setCurrentIndex(m_model->index(row, col), | - | ||||||||||||
| 1779 | QItemSelectionModel::NoUpdate); | - | ||||||||||||
| 1780 | } | - | ||||||||||||
| 1781 | } | - | ||||||||||||
| 1782 | - | |||||||||||||
| 1783 | void QCalendarWidgetPrivate::_q_monthChanged(QAction *act) | - | ||||||||||||
| 1784 | { | - | ||||||||||||
| 1785 | monthButton->setText(act->text()); | - | ||||||||||||
| 1786 | QDate currentDate = getCurrentDate(); | - | ||||||||||||
| 1787 | QDate newDate = currentDate.addMonths(act->data().toInt()-currentDate.month()); | - | ||||||||||||
| 1788 | updateCurrentPage(newDate); | - | ||||||||||||
| 1789 | } | - | ||||||||||||
| 1790 | - | |||||||||||||
| 1791 | QDate QCalendarWidgetPrivate::getCurrentDate() | - | ||||||||||||
| 1792 | { | - | ||||||||||||
| 1793 | QModelIndex index = m_view->currentIndex(); | - | ||||||||||||
| 1794 | return m_model->dateForCell(index.row(), index.column()); | - | ||||||||||||
| 1795 | } | - | ||||||||||||
| 1796 | - | |||||||||||||
| 1797 | void QCalendarWidgetPrivate::_q_prevMonthClicked() | - | ||||||||||||
| 1798 | { | - | ||||||||||||
| 1799 | QDate currentDate = getCurrentDate().addMonths(-1); | - | ||||||||||||
| 1800 | updateCurrentPage(currentDate); | - | ||||||||||||
| 1801 | } | - | ||||||||||||
| 1802 | - | |||||||||||||
| 1803 | void QCalendarWidgetPrivate::_q_nextMonthClicked() | - | ||||||||||||
| 1804 | { | - | ||||||||||||
| 1805 | QDate currentDate = getCurrentDate().addMonths(1); | - | ||||||||||||
| 1806 | updateCurrentPage(currentDate); | - | ||||||||||||
| 1807 | } | - | ||||||||||||
| 1808 | - | |||||||||||||
| 1809 | void QCalendarWidgetPrivate::_q_yearEditingFinished() | - | ||||||||||||
| 1810 | { | - | ||||||||||||
| 1811 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1812 | yearButton->setText(yearEdit->text()); | - | ||||||||||||
| 1813 | yearEdit->hide(); | - | ||||||||||||
| 1814 | q->setFocusPolicy(oldFocusPolicy); | - | ||||||||||||
| 1815 | (static_cast<QApplication *>(QCoreApplication::instance()))->removeEventFilter(q); | - | ||||||||||||
| 1816 | spaceHolder->changeSize(0, 0); | - | ||||||||||||
| 1817 | yearButton->show(); | - | ||||||||||||
| 1818 | QDate currentDate = getCurrentDate(); | - | ||||||||||||
| 1819 | currentDate = currentDate.addYears(yearEdit->text().toInt() - currentDate.year()); | - | ||||||||||||
| 1820 | updateCurrentPage(currentDate); | - | ||||||||||||
| 1821 | } | - | ||||||||||||
| 1822 | - | |||||||||||||
| 1823 | void QCalendarWidgetPrivate::_q_yearClicked() | - | ||||||||||||
| 1824 | { | - | ||||||||||||
| 1825 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1826 | - | |||||||||||||
| 1827 | yearEdit->setGeometry(yearButton->x(), yearButton->y(), | - | ||||||||||||
| 1828 | yearEdit->sizeHint().width(), yearButton->height()); | - | ||||||||||||
| 1829 | spaceHolder->changeSize(yearButton->width(), 0); | - | ||||||||||||
| 1830 | yearButton->hide(); | - | ||||||||||||
| 1831 | oldFocusPolicy = q->focusPolicy(); | - | ||||||||||||
| 1832 | q->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||
| 1833 | yearEdit->show(); | - | ||||||||||||
| 1834 | (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(q); | - | ||||||||||||
| 1835 | yearEdit->raise(); | - | ||||||||||||
| 1836 | yearEdit->selectAll(); | - | ||||||||||||
| 1837 | yearEdit->setFocus(Qt::MouseFocusReason); | - | ||||||||||||
| 1838 | } | - | ||||||||||||
| 1839 | - | |||||||||||||
| 1840 | void QCalendarWidgetPrivate::showMonth(int year, int month) | - | ||||||||||||
| 1841 | { | - | ||||||||||||
| 1842 | if (m_model->m_shownYear == year && m_model->m_shownMonth == month) | - | ||||||||||||
| 1843 | return; | - | ||||||||||||
| 1844 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1845 | m_model->showMonth(year, month); | - | ||||||||||||
| 1846 | updateNavigationBar(); | - | ||||||||||||
| 1847 | q->currentPageChanged(year, month); | - | ||||||||||||
| 1848 | m_view->internalUpdate(); | - | ||||||||||||
| 1849 | cachedSizeHint = QSize(); | - | ||||||||||||
| 1850 | update(); | - | ||||||||||||
| 1851 | updateMonthMenu(); | - | ||||||||||||
| 1852 | } | - | ||||||||||||
| 1853 | - | |||||||||||||
| 1854 | void QCalendarWidgetPrivate::updateNavigationBar() | - | ||||||||||||
| 1855 | { | - | ||||||||||||
| 1856 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1857 | - | |||||||||||||
| 1858 | QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat); | - | ||||||||||||
| 1859 | - | |||||||||||||
| 1860 | monthButton->setText(monthName); | - | ||||||||||||
| 1861 | yearButton->setText(QString::number(m_model->m_shownYear)); | - | ||||||||||||
| 1862 | yearEdit->setValue(m_model->m_shownYear); | - | ||||||||||||
| 1863 | } | - | ||||||||||||
| 1864 | - | |||||||||||||
| 1865 | void QCalendarWidgetPrivate::update() | - | ||||||||||||
| 1866 | { | - | ||||||||||||
| 1867 | QDate currentDate = m_model->m_date; | - | ||||||||||||
| 1868 | int row, column; | - | ||||||||||||
| 1869 | m_model->cellForDate(currentDate, &row, &column); | - | ||||||||||||
| 1870 | QModelIndex idx; | - | ||||||||||||
| 1871 | m_selection->clear(); | - | ||||||||||||
| 1872 | if (row != -1 && column != -1) { | - | ||||||||||||
| 1873 | idx = m_model->index(row, column); | - | ||||||||||||
| 1874 | m_selection->setCurrentIndex(idx, QItemSelectionModel::SelectCurrent); | - | ||||||||||||
| 1875 | } | - | ||||||||||||
| 1876 | } | - | ||||||||||||
| 1877 | - | |||||||||||||
| 1878 | void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||
| 1879 | { | - | ||||||||||||
| 1880 | const QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1881 | q->paintCell(painter, rect, date); | - | ||||||||||||
| 1882 | } | - | ||||||||||||
| 1883 | - | |||||||||||||
| 1884 | void QCalendarWidgetPrivate::_q_slotShowDate(const QDate &date) | - | ||||||||||||
| 1885 | { | - | ||||||||||||
| 1886 | updateCurrentPage(date); | - | ||||||||||||
| 1887 | } | - | ||||||||||||
| 1888 | - | |||||||||||||
| 1889 | void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date) | - | ||||||||||||
| 1890 | { | - | ||||||||||||
| 1891 | _q_slotChangeDate(date, true); | - | ||||||||||||
| 1892 | } | - | ||||||||||||
| 1893 | - | |||||||||||||
| 1894 | void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date, bool changeMonth) | - | ||||||||||||
| 1895 | { | - | ||||||||||||
| 1896 | QDate oldDate = m_model->m_date; | - | ||||||||||||
| 1897 | m_model->setDate(date); | - | ||||||||||||
| 1898 | QDate newDate = m_model->m_date; | - | ||||||||||||
| 1899 | if (changeMonth) | - | ||||||||||||
| 1900 | showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 1901 | if (oldDate != newDate) { | - | ||||||||||||
| 1902 | update(); | - | ||||||||||||
| 1903 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1904 | m_navigator->setDate(newDate); | - | ||||||||||||
| 1905 | q->selectionChanged(); | - | ||||||||||||
| 1906 | } | - | ||||||||||||
| 1907 | } | - | ||||||||||||
| 1908 | - | |||||||||||||
| 1909 | void QCalendarWidgetPrivate::_q_editingFinished() | - | ||||||||||||
| 1910 | { | - | ||||||||||||
| 1911 | QCalendarWidget * const q = q_func(); | - | ||||||||||||
| 1912 | q->activated(m_model->m_date); | - | ||||||||||||
| 1913 | } | - | ||||||||||||
| 1914 | QCalendarWidget::QCalendarWidget(QWidget *parent) | - | ||||||||||||
| 1915 | : QWidget(*new QCalendarWidgetPrivate, parent, 0) | - | ||||||||||||
| 1916 | { | - | ||||||||||||
| 1917 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 1918 | - | |||||||||||||
| 1919 | setAutoFillBackground(true); | - | ||||||||||||
| 1920 | setBackgroundRole(QPalette::Window); | - | ||||||||||||
| 1921 | - | |||||||||||||
| 1922 | QVBoxLayout *layoutV = new QVBoxLayout(this); | - | ||||||||||||
| 1923 | layoutV->setMargin(0); | - | ||||||||||||
| 1924 | d->m_model = new QCalendarModel(this); | - | ||||||||||||
| 1925 | QTextCharFormat fmt; | - | ||||||||||||
| 1926 | fmt.setForeground(QBrush(Qt::red)); | - | ||||||||||||
| 1927 | d->m_model->m_dayFormats.insert(Qt::Saturday, fmt); | - | ||||||||||||
| 1928 | d->m_model->m_dayFormats.insert(Qt::Sunday, fmt); | - | ||||||||||||
| 1929 | d->m_view = new QCalendarView(this); | - | ||||||||||||
| 1930 | d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview")); | - | ||||||||||||
| 1931 | d->m_view->setModel(d->m_model); | - | ||||||||||||
| 1932 | d->m_model->setView(d->m_view); | - | ||||||||||||
| 1933 | d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems); | - | ||||||||||||
| 1934 | d->m_view->setSelectionMode(QAbstractItemView::SingleSelection); | - | ||||||||||||
| 1935 | d->m_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | - | ||||||||||||
| 1936 | d->m_view->horizontalHeader()->setSectionsClickable(false); | - | ||||||||||||
| 1937 | d->m_view->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | - | ||||||||||||
| 1938 | d->m_view->verticalHeader()->setSectionsClickable(false); | - | ||||||||||||
| 1939 | d->m_selection = d->m_view->selectionModel(); | - | ||||||||||||
| 1940 | d->createNavigationBar(this); | - | ||||||||||||
| 1941 | d->m_view->setFrameStyle(QFrame::NoFrame); | - | ||||||||||||
| 1942 | d->m_delegate = new QCalendarDelegate(d, this); | - | ||||||||||||
| 1943 | d->m_view->setItemDelegate(d->m_delegate); | - | ||||||||||||
| 1944 | d->update(); | - | ||||||||||||
| 1945 | d->updateNavigationBar(); | - | ||||||||||||
| 1946 | setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||
| 1947 | setFocusProxy(d->m_view); | - | ||||||||||||
| 1948 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | - | ||||||||||||
| 1949 | - | |||||||||||||
| 1950 | connect(d->m_view, qFlagLocation("2""showDate(QDate)" "\0" __FILE__ ":" "2089""2125"), | - | ||||||||||||
| 1951 | this, qFlagLocation("1""_q_slotShowDate(QDate)" "\0" __FILE__ ":" "2090""2126")); | - | ||||||||||||
| 1952 | connect(d->m_view, qFlagLocation("2""changeDate(QDate,bool)" "\0" __FILE__ ":" "2091""2127"), | - | ||||||||||||
| 1953 | this, qFlagLocation("1""_q_slotChangeDate(QDate,bool)" "\0" __FILE__ ":" "2092""2128")); | - | ||||||||||||
| 1954 | connect(d->m_view, qFlagLocation("2""clicked(QDate)" "\0" __FILE__ ":" "2093""2129"), | - | ||||||||||||
| 1955 | this, qFlagLocation("2""clicked(QDate)" "\0" __FILE__ ":" "2094""2130")); | - | ||||||||||||
| 1956 | connect(d->m_view, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "2095""2131"), | - | ||||||||||||
| 1957 | this, qFlagLocation("1""_q_editingFinished()" "\0" __FILE__ ":" "2096""2132")); | - | ||||||||||||
| 1958 | - | |||||||||||||
| 1959 | connect(d->prevMonth, qFlagLocation("2""clicked(bool)" "\0" __FILE__ ":" "2098""2134"), | - | ||||||||||||
| 1960 | this, qFlagLocation("1""_q_prevMonthClicked()" "\0" __FILE__ ":" "2099""2135")); | - | ||||||||||||
| 1961 | connect(d->nextMonth, qFlagLocation("2""clicked(bool)" "\0" __FILE__ ":" "2100""2136"), | - | ||||||||||||
| 1962 | this, qFlagLocation("1""_q_nextMonthClicked()" "\0" __FILE__ ":" "2101""2137")); | - | ||||||||||||
| 1963 | connect(d->yearButton, qFlagLocation("2""clicked(bool)" "\0" __FILE__ ":" "2102""2138"), | - | ||||||||||||
| 1964 | this, qFlagLocation("1""_q_yearClicked()" "\0" __FILE__ ":" "2103""2139")); | - | ||||||||||||
| 1965 | connect(d->monthMenu, qFlagLocation("2""triggered(QAction*)" "\0" __FILE__ ":" "2104""2140"), | - | ||||||||||||
| 1966 | this, qFlagLocation("1""_q_monthChanged(QAction*)" "\0" __FILE__ ":" "2105""2141")); | - | ||||||||||||
| 1967 | connect(d->yearEdit, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "2106""2142"), | - | ||||||||||||
| 1968 | this, qFlagLocation("1""_q_yearEditingFinished()" "\0" __FILE__ ":" "2107""2143")); | - | ||||||||||||
| 1969 | - | |||||||||||||
| 1970 | layoutV->setMargin(0); | - | ||||||||||||
| 1971 | layoutV->setSpacing(0); | - | ||||||||||||
| 1972 | layoutV->addWidget(d->navBarBackground); | - | ||||||||||||
| 1973 | layoutV->addWidget(d->m_view); | - | ||||||||||||
| 1974 | - | |||||||||||||
| 1975 | d->m_navigator = new QCalendarTextNavigator(this); | - | ||||||||||||
| 1976 | setDateEditEnabled(true); | - | ||||||||||||
| 1977 | } | - | ||||||||||||
| 1978 | - | |||||||||||||
| 1979 | - | |||||||||||||
| 1980 | - | |||||||||||||
| 1981 | - | |||||||||||||
| 1982 | QCalendarWidget::~QCalendarWidget() | - | ||||||||||||
| 1983 | { | - | ||||||||||||
| 1984 | } | - | ||||||||||||
| 1985 | - | |||||||||||||
| 1986 | - | |||||||||||||
| 1987 | - | |||||||||||||
| 1988 | - | |||||||||||||
| 1989 | QSize QCalendarWidget::sizeHint() const | - | ||||||||||||
| 1990 | { | - | ||||||||||||
| 1991 | return minimumSizeHint(); | - | ||||||||||||
| 1992 | } | - | ||||||||||||
| 1993 | - | |||||||||||||
| 1994 | - | |||||||||||||
| 1995 | - | |||||||||||||
| 1996 | - | |||||||||||||
| 1997 | QSize QCalendarWidget::minimumSizeHint() const | - | ||||||||||||
| 1998 | { | - | ||||||||||||
| 1999 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2000 | if (d->cachedSizeHint.isValid()) | - | ||||||||||||
| 2001 | return d->cachedSizeHint; | - | ||||||||||||
| 2002 | - | |||||||||||||
| 2003 | ensurePolished(); | - | ||||||||||||
| 2004 | - | |||||||||||||
| 2005 | int w = 0; | - | ||||||||||||
| 2006 | int h = 0; | - | ||||||||||||
| 2007 | - | |||||||||||||
| 2008 | int end = 53; | - | ||||||||||||
| 2009 | int rows = 7; | - | ||||||||||||
| 2010 | int cols = 8; | - | ||||||||||||
| 2011 | - | |||||||||||||
| 2012 | const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2; | - | ||||||||||||
| 2013 | - | |||||||||||||
| 2014 | if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) { | - | ||||||||||||
| 2015 | rows = 6; | - | ||||||||||||
| 2016 | } else { | - | ||||||||||||
| 2017 | for (int i = 1; i <= 7; i++) { | - | ||||||||||||
| 2018 | QFontMetrics fm(d->m_model->formatForCell(0, i).font()); | - | ||||||||||||
| 2019 | w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH); | - | ||||||||||||
| 2020 | h = qMax(h, fm.height()); | - | ||||||||||||
| 2021 | } | - | ||||||||||||
| 2022 | } | - | ||||||||||||
| 2023 | - | |||||||||||||
| 2024 | if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) { | - | ||||||||||||
| 2025 | cols = 7; | - | ||||||||||||
| 2026 | } else { | - | ||||||||||||
| 2027 | for (int i = 1; i <= 6; i++) { | - | ||||||||||||
| 2028 | QFontMetrics fm(d->m_model->formatForCell(i, 0).font()); | - | ||||||||||||
| 2029 | for (int j = 1; j < end; j++) | - | ||||||||||||
| 2030 | w = qMax(w, fm.width(QString::number(j)) + marginH); | - | ||||||||||||
| 2031 | h = qMax(h, fm.height()); | - | ||||||||||||
| 2032 | } | - | ||||||||||||
| 2033 | } | - | ||||||||||||
| 2034 | - | |||||||||||||
| 2035 | QFontMetrics fm(d->m_model->formatForCell(1, 1).font()); | - | ||||||||||||
| 2036 | for (int i = 1; i <= end; i++) { | - | ||||||||||||
| 2037 | w = qMax(w, fm.width(QString::number(i)) + marginH); | - | ||||||||||||
| 2038 | h = qMax(h, fm.height()); | - | ||||||||||||
| 2039 | } | - | ||||||||||||
| 2040 | - | |||||||||||||
| 2041 | if (d->m_view->showGrid()) { | - | ||||||||||||
| 2042 | - | |||||||||||||
| 2043 | w += 1; | - | ||||||||||||
| 2044 | h += 1; | - | ||||||||||||
| 2045 | } | - | ||||||||||||
| 2046 | - | |||||||||||||
| 2047 | w += 1; | - | ||||||||||||
| 2048 | - | |||||||||||||
| 2049 | h = qMax(h, d->m_view->verticalHeader()->minimumSectionSize()); | - | ||||||||||||
| 2050 | w = qMax(w, d->m_view->horizontalHeader()->minimumSectionSize()); | - | ||||||||||||
| 2051 | - | |||||||||||||
| 2052 | - | |||||||||||||
| 2053 | QSize headerSize(0, 0); | - | ||||||||||||
| 2054 | if (d->navBarVisible) { | - | ||||||||||||
| 2055 | int headerH = d->navBarBackground->sizeHint().height(); | - | ||||||||||||
| 2056 | int headerW = 0; | - | ||||||||||||
| 2057 | - | |||||||||||||
| 2058 | headerW += d->prevMonth->sizeHint().width(); | - | ||||||||||||
| 2059 | headerW += d->nextMonth->sizeHint().width(); | - | ||||||||||||
| 2060 | - | |||||||||||||
| 2061 | QFontMetrics fm = d->monthButton->fontMetrics(); | - | ||||||||||||
| 2062 | int monthW = 0; | - | ||||||||||||
| 2063 | for (int i = 1; i < 12; i++) { | - | ||||||||||||
| 2064 | QString monthName = locale().standaloneMonthName(i, QLocale::LongFormat); | - | ||||||||||||
| 2065 | monthW = qMax(monthW, fm.boundingRect(monthName).width()); | - | ||||||||||||
| 2066 | } | - | ||||||||||||
| 2067 | const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width(); | - | ||||||||||||
| 2068 | headerW += monthW + buttonDecoMargin; | - | ||||||||||||
| 2069 | - | |||||||||||||
| 2070 | fm = d->yearButton->fontMetrics(); | - | ||||||||||||
| 2071 | headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin; | - | ||||||||||||
| 2072 | - | |||||||||||||
| 2073 | headerSize = QSize(headerW, headerH); | - | ||||||||||||
| 2074 | } | - | ||||||||||||
| 2075 | w *= cols; | - | ||||||||||||
| 2076 | w = qMax(headerSize.width(), w); | - | ||||||||||||
| 2077 | h = (h * rows) + headerSize.height(); | - | ||||||||||||
| 2078 | QMargins cm = contentsMargins(); | - | ||||||||||||
| 2079 | w += cm.left() + cm.right(); | - | ||||||||||||
| 2080 | h += cm.top() + cm.bottom(); | - | ||||||||||||
| 2081 | d->cachedSizeHint = QSize(w, h); | - | ||||||||||||
| 2082 | return d->cachedSizeHint; | - | ||||||||||||
| 2083 | } | - | ||||||||||||
| 2084 | - | |||||||||||||
| 2085 | - | |||||||||||||
| 2086 | - | |||||||||||||
| 2087 | - | |||||||||||||
| 2088 | - | |||||||||||||
| 2089 | void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||
| 2090 | { | - | ||||||||||||
| 2091 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2092 | d->m_delegate->paintCell(painter, rect, date); | - | ||||||||||||
| 2093 | } | - | ||||||||||||
| 2094 | QDate QCalendarWidget::selectedDate() const | - | ||||||||||||
| 2095 | { | - | ||||||||||||
| 2096 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2097 | return d->m_model->m_date; | - | ||||||||||||
| 2098 | } | - | ||||||||||||
| 2099 | - | |||||||||||||
| 2100 | void QCalendarWidget::setSelectedDate(const QDate &date) | - | ||||||||||||
| 2101 | { | - | ||||||||||||
| 2102 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2103 | if (d->m_model->m_date == date && date == d->getCurrentDate()) | - | ||||||||||||
| 2104 | return; | - | ||||||||||||
| 2105 | - | |||||||||||||
| 2106 | if (!date.isValid()) | - | ||||||||||||
| 2107 | return; | - | ||||||||||||
| 2108 | - | |||||||||||||
| 2109 | d->m_model->setDate(date); | - | ||||||||||||
| 2110 | d->update(); | - | ||||||||||||
| 2111 | QDate newDate = d->m_model->m_date; | - | ||||||||||||
| 2112 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 2113 | selectionChanged(); | - | ||||||||||||
| 2114 | } | - | ||||||||||||
| 2115 | int QCalendarWidget::yearShown() const | - | ||||||||||||
| 2116 | { | - | ||||||||||||
| 2117 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2118 | return d->m_model->m_shownYear; | - | ||||||||||||
| 2119 | } | - | ||||||||||||
| 2120 | int QCalendarWidget::monthShown() const | - | ||||||||||||
| 2121 | { | - | ||||||||||||
| 2122 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2123 | return d->m_model->m_shownMonth; | - | ||||||||||||
| 2124 | } | - | ||||||||||||
| 2125 | void QCalendarWidget::setCurrentPage(int year, int month) | - | ||||||||||||
| 2126 | { | - | ||||||||||||
| 2127 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2128 | QDate currentDate = d->getCurrentDate(); | - | ||||||||||||
| 2129 | int day = currentDate.day(); | - | ||||||||||||
| 2130 | int daysInMonths = QDate(year, month, 1).daysInMonth(); | - | ||||||||||||
| 2131 | if (day > daysInMonths) | - | ||||||||||||
| 2132 | day = daysInMonths; | - | ||||||||||||
| 2133 | - | |||||||||||||
| 2134 | d->showMonth(year, month); | - | ||||||||||||
| 2135 | - | |||||||||||||
| 2136 | QDate newDate(year, month, day); | - | ||||||||||||
| 2137 | int row = -1, col = -1; | - | ||||||||||||
| 2138 | d->m_model->cellForDate(newDate, &row, &col); | - | ||||||||||||
| 2139 | if (row != -1 && col != -1) { | - | ||||||||||||
| 2140 | d->m_view->selectionModel()->setCurrentIndex(d->m_model->index(row, col), | - | ||||||||||||
| 2141 | QItemSelectionModel::NoUpdate); | - | ||||||||||||
| 2142 | } | - | ||||||||||||
| 2143 | } | - | ||||||||||||
| 2144 | void QCalendarWidget::showNextMonth() | - | ||||||||||||
| 2145 | { | - | ||||||||||||
| 2146 | int year = yearShown(); | - | ||||||||||||
| 2147 | int month = monthShown(); | - | ||||||||||||
| 2148 | if (month == 12) { | - | ||||||||||||
| 2149 | ++year; | - | ||||||||||||
| 2150 | month = 1; | - | ||||||||||||
| 2151 | } else { | - | ||||||||||||
| 2152 | ++month; | - | ||||||||||||
| 2153 | } | - | ||||||||||||
| 2154 | setCurrentPage(year, month); | - | ||||||||||||
| 2155 | } | - | ||||||||||||
| 2156 | void QCalendarWidget::showPreviousMonth() | - | ||||||||||||
| 2157 | { | - | ||||||||||||
| 2158 | int year = yearShown(); | - | ||||||||||||
| 2159 | int month = monthShown(); | - | ||||||||||||
| 2160 | if (month == 1) { | - | ||||||||||||
| 2161 | --year; | - | ||||||||||||
| 2162 | month = 12; | - | ||||||||||||
| 2163 | } else { | - | ||||||||||||
| 2164 | --month; | - | ||||||||||||
| 2165 | } | - | ||||||||||||
| 2166 | setCurrentPage(year, month); | - | ||||||||||||
| 2167 | } | - | ||||||||||||
| 2168 | void QCalendarWidget::showNextYear() | - | ||||||||||||
| 2169 | { | - | ||||||||||||
| 2170 | int year = yearShown(); | - | ||||||||||||
| 2171 | int month = monthShown(); | - | ||||||||||||
| 2172 | ++year; | - | ||||||||||||
| 2173 | setCurrentPage(year, month); | - | ||||||||||||
| 2174 | } | - | ||||||||||||
| 2175 | void QCalendarWidget::showPreviousYear() | - | ||||||||||||
| 2176 | { | - | ||||||||||||
| 2177 | int year = yearShown(); | - | ||||||||||||
| 2178 | int month = monthShown(); | - | ||||||||||||
| 2179 | --year; | - | ||||||||||||
| 2180 | setCurrentPage(year, month); | - | ||||||||||||
| 2181 | } | - | ||||||||||||
| 2182 | - | |||||||||||||
| 2183 | - | |||||||||||||
| 2184 | - | |||||||||||||
| 2185 | - | |||||||||||||
| 2186 | - | |||||||||||||
| 2187 | - | |||||||||||||
| 2188 | void QCalendarWidget::showSelectedDate() | - | ||||||||||||
| 2189 | { | - | ||||||||||||
| 2190 | QDate currentDate = selectedDate(); | - | ||||||||||||
| 2191 | setCurrentPage(currentDate.year(), currentDate.month()); | - | ||||||||||||
| 2192 | } | - | ||||||||||||
| 2193 | - | |||||||||||||
| 2194 | - | |||||||||||||
| 2195 | - | |||||||||||||
| 2196 | - | |||||||||||||
| 2197 | - | |||||||||||||
| 2198 | - | |||||||||||||
| 2199 | void QCalendarWidget::showToday() | - | ||||||||||||
| 2200 | { | - | ||||||||||||
| 2201 | QDate currentDate = QDate::currentDate(); | - | ||||||||||||
| 2202 | setCurrentPage(currentDate.year(), currentDate.month()); | - | ||||||||||||
| 2203 | } | - | ||||||||||||
| 2204 | QDate QCalendarWidget::minimumDate() const | - | ||||||||||||
| 2205 | { | - | ||||||||||||
| 2206 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2207 | return d->m_model->m_minimumDate; | - | ||||||||||||
| 2208 | } | - | ||||||||||||
| 2209 | - | |||||||||||||
| 2210 | void QCalendarWidget::setMinimumDate(const QDate &date) | - | ||||||||||||
| 2211 | { | - | ||||||||||||
| 2212 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2213 | if (!date.isValid() || d->m_model->m_minimumDate == date) | - | ||||||||||||
| 2214 | return; | - | ||||||||||||
| 2215 | - | |||||||||||||
| 2216 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||
| 2217 | d->m_model->setMinimumDate(date); | - | ||||||||||||
| 2218 | d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); | - | ||||||||||||
| 2219 | d->updateMonthMenu(); | - | ||||||||||||
| 2220 | QDate newDate = d->m_model->m_date; | - | ||||||||||||
| 2221 | if (oldDate != newDate) { | - | ||||||||||||
| 2222 | d->update(); | - | ||||||||||||
| 2223 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 2224 | d->m_navigator->setDate(newDate); | - | ||||||||||||
| 2225 | selectionChanged(); | - | ||||||||||||
| 2226 | } | - | ||||||||||||
| 2227 | } | - | ||||||||||||
| 2228 | QDate QCalendarWidget::maximumDate() const | - | ||||||||||||
| 2229 | { | - | ||||||||||||
| 2230 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2231 | return d->m_model->m_maximumDate; | - | ||||||||||||
| 2232 | } | - | ||||||||||||
| 2233 | - | |||||||||||||
| 2234 | void QCalendarWidget::setMaximumDate(const QDate &date) | - | ||||||||||||
| 2235 | { | - | ||||||||||||
| 2236 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2237 | if (!date.isValid() || d->m_model->m_maximumDate == date) | - | ||||||||||||
| 2238 | return; | - | ||||||||||||
| 2239 | - | |||||||||||||
| 2240 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||
| 2241 | d->m_model->setMaximumDate(date); | - | ||||||||||||
| 2242 | d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); | - | ||||||||||||
| 2243 | d->updateMonthMenu(); | - | ||||||||||||
| 2244 | QDate newDate = d->m_model->m_date; | - | ||||||||||||
| 2245 | if (oldDate != newDate) { | - | ||||||||||||
| 2246 | d->update(); | - | ||||||||||||
| 2247 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 2248 | d->m_navigator->setDate(newDate); | - | ||||||||||||
| 2249 | selectionChanged(); | - | ||||||||||||
| 2250 | } | - | ||||||||||||
| 2251 | } | - | ||||||||||||
| 2252 | void QCalendarWidget::setDateRange(const QDate &min, const QDate &max) | - | ||||||||||||
| 2253 | { | - | ||||||||||||
| 2254 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2255 | if (d->m_model->m_minimumDate == min && d->m_model->m_maximumDate == max) | - | ||||||||||||
| 2256 | return; | - | ||||||||||||
| 2257 | if (!min.isValid() || !max.isValid()) | - | ||||||||||||
| 2258 | return; | - | ||||||||||||
| 2259 | - | |||||||||||||
| 2260 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||
| 2261 | d->m_model->setRange(min, max); | - | ||||||||||||
| 2262 | d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); | - | ||||||||||||
| 2263 | d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); | - | ||||||||||||
| 2264 | d->updateMonthMenu(); | - | ||||||||||||
| 2265 | QDate newDate = d->m_model->m_date; | - | ||||||||||||
| 2266 | if (oldDate != newDate) { | - | ||||||||||||
| 2267 | d->update(); | - | ||||||||||||
| 2268 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||
| 2269 | d->m_navigator->setDate(newDate); | - | ||||||||||||
| 2270 | selectionChanged(); | - | ||||||||||||
| 2271 | } | - | ||||||||||||
| 2272 | } | - | ||||||||||||
| 2273 | void QCalendarWidget::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) | - | ||||||||||||
| 2274 | { | - | ||||||||||||
| 2275 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2276 | if (d->m_model->m_horizontalHeaderFormat == format) | - | ||||||||||||
| 2277 | return; | - | ||||||||||||
| 2278 | - | |||||||||||||
| 2279 | d->m_model->setHorizontalHeaderFormat(format); | - | ||||||||||||
| 2280 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2281 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2282 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2283 | } | - | ||||||||||||
| 2284 | - | |||||||||||||
| 2285 | QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat() const | - | ||||||||||||
| 2286 | { | - | ||||||||||||
| 2287 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2288 | return d->m_model->m_horizontalHeaderFormat; | - | ||||||||||||
| 2289 | } | - | ||||||||||||
| 2290 | QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat() const | - | ||||||||||||
| 2291 | { | - | ||||||||||||
| 2292 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2293 | bool shown = d->m_model->weekNumbersShown(); | - | ||||||||||||
| 2294 | if (shown) | - | ||||||||||||
| 2295 | return QCalendarWidget::ISOWeekNumbers; | - | ||||||||||||
| 2296 | return QCalendarWidget::NoVerticalHeader; | - | ||||||||||||
| 2297 | } | - | ||||||||||||
| 2298 | - | |||||||||||||
| 2299 | void QCalendarWidget::setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat format) | - | ||||||||||||
| 2300 | { | - | ||||||||||||
| 2301 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2302 | bool show = false; | - | ||||||||||||
| 2303 | if (format == QCalendarWidget::ISOWeekNumbers) | - | ||||||||||||
| 2304 | show = true; | - | ||||||||||||
| 2305 | if (d->m_model->weekNumbersShown() == show) | - | ||||||||||||
| 2306 | return; | - | ||||||||||||
| 2307 | d->m_model->setWeekNumbersShown(show); | - | ||||||||||||
| 2308 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2309 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2310 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2311 | } | - | ||||||||||||
| 2312 | bool QCalendarWidget::isGridVisible() const | - | ||||||||||||
| 2313 | { | - | ||||||||||||
| 2314 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2315 | return d->m_view->showGrid(); | - | ||||||||||||
| 2316 | } | - | ||||||||||||
| 2317 | - | |||||||||||||
| 2318 | void QCalendarWidget::setGridVisible(bool show) | - | ||||||||||||
| 2319 | { | - | ||||||||||||
| 2320 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2321 | d->m_view->setShowGrid(show); | - | ||||||||||||
| 2322 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2323 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2324 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2325 | } | - | ||||||||||||
| 2326 | QCalendarWidget::SelectionMode QCalendarWidget::selectionMode() const | - | ||||||||||||
| 2327 | { | - | ||||||||||||
| 2328 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2329 | return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection; | - | ||||||||||||
| 2330 | } | - | ||||||||||||
| 2331 | - | |||||||||||||
| 2332 | void QCalendarWidget::setSelectionMode(SelectionMode mode) | - | ||||||||||||
| 2333 | { | - | ||||||||||||
| 2334 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2335 | d->m_view->readOnly = (mode == QCalendarWidget::NoSelection); | - | ||||||||||||
| 2336 | d->setNavigatorEnabled(isDateEditEnabled() && (selectionMode() != QCalendarWidget::NoSelection)); | - | ||||||||||||
| 2337 | d->update(); | - | ||||||||||||
| 2338 | } | - | ||||||||||||
| 2339 | void QCalendarWidget::setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek) | - | ||||||||||||
| 2340 | { | - | ||||||||||||
| 2341 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2342 | if ((Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek) | - | ||||||||||||
| 2343 | return; | - | ||||||||||||
| 2344 | - | |||||||||||||
| 2345 | d->m_model->setFirstColumnDay(dayOfWeek); | - | ||||||||||||
| 2346 | d->update(); | - | ||||||||||||
| 2347 | } | - | ||||||||||||
| 2348 | - | |||||||||||||
| 2349 | Qt::DayOfWeek QCalendarWidget::firstDayOfWeek() const | - | ||||||||||||
| 2350 | { | - | ||||||||||||
| 2351 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2352 | return (Qt::DayOfWeek)d->m_model->firstColumnDay(); | - | ||||||||||||
| 2353 | } | - | ||||||||||||
| 2354 | - | |||||||||||||
| 2355 | - | |||||||||||||
| 2356 | - | |||||||||||||
| 2357 | - | |||||||||||||
| 2358 | QTextCharFormat QCalendarWidget::headerTextFormat() const | - | ||||||||||||
| 2359 | { | - | ||||||||||||
| 2360 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2361 | return d->m_model->m_headerFormat; | - | ||||||||||||
| 2362 | } | - | ||||||||||||
| 2363 | void QCalendarWidget::setHeaderTextFormat(const QTextCharFormat &format) | - | ||||||||||||
| 2364 | { | - | ||||||||||||
| 2365 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2366 | d->m_model->m_headerFormat = format; | - | ||||||||||||
| 2367 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2368 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2369 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2370 | } | - | ||||||||||||
| 2371 | - | |||||||||||||
| 2372 | - | |||||||||||||
| 2373 | - | |||||||||||||
| 2374 | - | |||||||||||||
| 2375 | - | |||||||||||||
| 2376 | - | |||||||||||||
| 2377 | QTextCharFormat QCalendarWidget::weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const | - | ||||||||||||
| 2378 | { | - | ||||||||||||
| 2379 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2380 | return d->m_model->m_dayFormats.value(dayOfWeek); | - | ||||||||||||
| 2381 | } | - | ||||||||||||
| 2382 | void QCalendarWidget::setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format) | - | ||||||||||||
| 2383 | { | - | ||||||||||||
| 2384 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2385 | d->m_model->m_dayFormats[dayOfWeek] = format; | - | ||||||||||||
| 2386 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2387 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2388 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2389 | } | - | ||||||||||||
| 2390 | - | |||||||||||||
| 2391 | - | |||||||||||||
| 2392 | - | |||||||||||||
| 2393 | - | |||||||||||||
| 2394 | - | |||||||||||||
| 2395 | QMap<QDate, QTextCharFormat> QCalendarWidget::dateTextFormat() const | - | ||||||||||||
| 2396 | { | - | ||||||||||||
| 2397 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2398 | return d->m_model->m_dateFormats; | - | ||||||||||||
| 2399 | } | - | ||||||||||||
| 2400 | - | |||||||||||||
| 2401 | - | |||||||||||||
| 2402 | - | |||||||||||||
| 2403 | - | |||||||||||||
| 2404 | - | |||||||||||||
| 2405 | QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const | - | ||||||||||||
| 2406 | { | - | ||||||||||||
| 2407 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2408 | return d->m_model->m_dateFormats.value(date); | - | ||||||||||||
| 2409 | } | - | ||||||||||||
| 2410 | - | |||||||||||||
| 2411 | - | |||||||||||||
| 2412 | - | |||||||||||||
| 2413 | - | |||||||||||||
| 2414 | - | |||||||||||||
| 2415 | - | |||||||||||||
| 2416 | void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format) | - | ||||||||||||
| 2417 | { | - | ||||||||||||
| 2418 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2419 | if (date.isNull()) | - | ||||||||||||
| 2420 | d->m_model->m_dateFormats.clear(); | - | ||||||||||||
| 2421 | else | - | ||||||||||||
| 2422 | d->m_model->m_dateFormats[date] = format; | - | ||||||||||||
| 2423 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2424 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2425 | } | - | ||||||||||||
| 2426 | bool QCalendarWidget::isDateEditEnabled() const | - | ||||||||||||
| 2427 | { | - | ||||||||||||
| 2428 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2429 | return d->m_dateEditEnabled; | - | ||||||||||||
| 2430 | } | - | ||||||||||||
| 2431 | - | |||||||||||||
| 2432 | void QCalendarWidget::setDateEditEnabled(bool enable) | - | ||||||||||||
| 2433 | { | - | ||||||||||||
| 2434 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2435 | if (isDateEditEnabled() == enable) | - | ||||||||||||
| 2436 | return; | - | ||||||||||||
| 2437 | - | |||||||||||||
| 2438 | d->m_dateEditEnabled = enable; | - | ||||||||||||
| 2439 | - | |||||||||||||
| 2440 | d->setNavigatorEnabled(enable && (selectionMode() != QCalendarWidget::NoSelection)); | - | ||||||||||||
| 2441 | } | - | ||||||||||||
| 2442 | int QCalendarWidget::dateEditAcceptDelay() const | - | ||||||||||||
| 2443 | { | - | ||||||||||||
| 2444 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2445 | return d->m_navigator->dateEditAcceptDelay(); | - | ||||||||||||
| 2446 | } | - | ||||||||||||
| 2447 | - | |||||||||||||
| 2448 | void QCalendarWidget::setDateEditAcceptDelay(int delay) | - | ||||||||||||
| 2449 | { | - | ||||||||||||
| 2450 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2451 | d->m_navigator->setDateEditAcceptDelay(delay); | - | ||||||||||||
| 2452 | } | - | ||||||||||||
| 2453 | void QCalendarWidget::updateCell(const QDate &date) | - | ||||||||||||
| 2454 | { | - | ||||||||||||
| 2455 | if (!(__builtin_expect(!!(!
| 0 | ||||||||||||
| 2456 | QMessageLogger(__FILE__, 28842920, __PRETTY_FUNCTION__).warning("QCalendarWidget::updateCell: Invalid date"); | - | ||||||||||||
| 2457 | return; never executed: return; | 0 | ||||||||||||
| 2458 | } | - | ||||||||||||
| 2459 | - | |||||||||||||
| 2460 | if (!isVisible()
| 0 | ||||||||||||
| 2461 | return; never executed: return; | 0 | ||||||||||||
| 2462 | - | |||||||||||||
| 2463 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2464 | int row, column; | - | ||||||||||||
| 2465 | d->m_model->cellForDate(date, &row, &column); | - | ||||||||||||
| 2466 | if (row == -1
| 0 | ||||||||||||
| 2467 | return; never executed: return; | 0 | ||||||||||||
| 2468 | - | |||||||||||||
| 2469 | QModelIndex modelIndex = d->m_model->index(row, column); | - | ||||||||||||
| 2470 | if (!modelIndex.isValid()
| 0 | ||||||||||||
| 2471 | return; never executed: return; | 0 | ||||||||||||
| 2472 | - | |||||||||||||
| 2473 | d->m_view->viewport()->update(d->m_view->visualRect(modelIndex)); | - | ||||||||||||
| 2474 | } never executed: end of block | 0 | ||||||||||||
| 2475 | void QCalendarWidget::updateCells() | - | ||||||||||||
| 2476 | { | - | ||||||||||||
| 2477 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2478 | if (isVisible()) | - | ||||||||||||
| 2479 | d->m_view->viewport()->update(); | - | ||||||||||||
| 2480 | } | - | ||||||||||||
| 2481 | bool QCalendarWidget::isNavigationBarVisible() const | - | ||||||||||||
| 2482 | { | - | ||||||||||||
| 2483 | const QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2484 | return d->navBarVisible; | - | ||||||||||||
| 2485 | } | - | ||||||||||||
| 2486 | - | |||||||||||||
| 2487 | - | |||||||||||||
| 2488 | void QCalendarWidget::setNavigationBarVisible(bool visible) | - | ||||||||||||
| 2489 | { | - | ||||||||||||
| 2490 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2491 | d->navBarVisible = visible; | - | ||||||||||||
| 2492 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2493 | d->navBarBackground->setVisible(visible); | - | ||||||||||||
| 2494 | updateGeometry(); | - | ||||||||||||
| 2495 | } | - | ||||||||||||
| 2496 | - | |||||||||||||
| 2497 | - | |||||||||||||
| 2498 | - | |||||||||||||
| 2499 | - | |||||||||||||
| 2500 | bool QCalendarWidget::event(QEvent *event) | - | ||||||||||||
| 2501 | { | - | ||||||||||||
| 2502 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2503 | switch (event->type()) { | - | ||||||||||||
| 2504 | case QEvent::LayoutDirectionChange: | - | ||||||||||||
| 2505 | d->updateButtonIcons(); | - | ||||||||||||
| 2506 | break; | - | ||||||||||||
| 2507 | case QEvent::LocaleChange: | - | ||||||||||||
| 2508 | d->m_model->setFirstColumnDay(locale().firstDayOfWeek()); | - | ||||||||||||
| 2509 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2510 | d->updateMonthMenuNames(); | - | ||||||||||||
| 2511 | d->updateNavigationBar(); | - | ||||||||||||
| 2512 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2513 | break; | - | ||||||||||||
| 2514 | case QEvent::FontChange: | - | ||||||||||||
| 2515 | case QEvent::ApplicationFontChange: | - | ||||||||||||
| 2516 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2517 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2518 | break; | - | ||||||||||||
| 2519 | case QEvent::StyleChange: | - | ||||||||||||
| 2520 | d->cachedSizeHint = QSize(); | - | ||||||||||||
| 2521 | d->m_view->updateGeometry(); | - | ||||||||||||
| 2522 | default: | - | ||||||||||||
| 2523 | break; | - | ||||||||||||
| 2524 | } | - | ||||||||||||
| 2525 | return QWidget::event(event); | - | ||||||||||||
| 2526 | } | - | ||||||||||||
| 2527 | - | |||||||||||||
| 2528 | - | |||||||||||||
| 2529 | - | |||||||||||||
| 2530 | - | |||||||||||||
| 2531 | bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) | - | ||||||||||||
| 2532 | { | - | ||||||||||||
| 2533 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2534 | if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) { | - | ||||||||||||
| 2535 | QWidget *tlw = window(); | - | ||||||||||||
| 2536 | QWidget *widget = static_cast<QWidget*>(watched); | - | ||||||||||||
| 2537 | - | |||||||||||||
| 2538 | - | |||||||||||||
| 2539 | if (widget->window() == tlw) { | - | ||||||||||||
| 2540 | QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); | - | ||||||||||||
| 2541 | QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); | - | ||||||||||||
| 2542 | if (!geom.contains(mousePos)) { | - | ||||||||||||
| 2543 | event->accept(); | - | ||||||||||||
| 2544 | d->_q_yearEditingFinished(); | - | ||||||||||||
| 2545 | setFocus(); | - | ||||||||||||
| 2546 | return true; | - | ||||||||||||
| 2547 | } | - | ||||||||||||
| 2548 | } | - | ||||||||||||
| 2549 | } | - | ||||||||||||
| 2550 | return QWidget::eventFilter(watched, event); | - | ||||||||||||
| 2551 | } | - | ||||||||||||
| 2552 | - | |||||||||||||
| 2553 | - | |||||||||||||
| 2554 | - | |||||||||||||
| 2555 | - | |||||||||||||
| 2556 | void QCalendarWidget::mousePressEvent(QMouseEvent *event) | - | ||||||||||||
| 2557 | { | - | ||||||||||||
| 2558 | setAttribute(Qt::WA_NoMouseReplay); | - | ||||||||||||
| 2559 | QWidget::mousePressEvent(event); | - | ||||||||||||
| 2560 | setFocus(); | - | ||||||||||||
| 2561 | } | - | ||||||||||||
| 2562 | - | |||||||||||||
| 2563 | - | |||||||||||||
| 2564 | - | |||||||||||||
| 2565 | - | |||||||||||||
| 2566 | void QCalendarWidget::resizeEvent(QResizeEvent * event) | - | ||||||||||||
| 2567 | { | - | ||||||||||||
| 2568 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2569 | - | |||||||||||||
| 2570 | - | |||||||||||||
| 2571 | - | |||||||||||||
| 2572 | - | |||||||||||||
| 2573 | if(d->yearEdit->isVisible() && event->size().width() != event->oldSize().width()) | - | ||||||||||||
| 2574 | d->_q_yearEditingFinished(); | - | ||||||||||||
| 2575 | - | |||||||||||||
| 2576 | QWidget::resizeEvent(event); | - | ||||||||||||
| 2577 | } | - | ||||||||||||
| 2578 | - | |||||||||||||
| 2579 | - | |||||||||||||
| 2580 | - | |||||||||||||
| 2581 | - | |||||||||||||
| 2582 | void QCalendarWidget::keyPressEvent(QKeyEvent * event) | - | ||||||||||||
| 2583 | { | - | ||||||||||||
| 2584 | QCalendarWidgetPrivate * const d = d_func(); | - | ||||||||||||
| 2585 | if (d->yearEdit->isVisible()&& event->matches(QKeySequence::Cancel)) { | - | ||||||||||||
| 2586 | d->yearEdit->setValue(yearShown()); | - | ||||||||||||
| 2587 | d->_q_yearEditingFinished(); | - | ||||||||||||
| 2588 | return; | - | ||||||||||||
| 2589 | } | - | ||||||||||||
| 2590 | QWidget::keyPressEvent(event); | - | ||||||||||||
| 2591 | } | - | ||||||||||||
| 2592 | - | |||||||||||||
| 2593 | - | |||||||||||||
| 2594 | - | |||||||||||||
| Switch to Source code | Preprocessed file |