diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ ) # Build dependencies -find_package(KF5 REQUIRED COMPONENTS KDELibs4Support Archive DocTools) +find_package(KF5 REQUIRED COMPONENTS KDELibs4Support Archive DocTools WidgetsAddons) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,6 @@ kfinddlg.cpp kftabdlg.cpp kquery.cpp - kdatecombo.cpp kfindtreeview.cpp) file(GLOB ICONS_SRCS "../icons/*-apps-kfind.png") diff --git a/src/kdatecombo.h b/src/kdatecombo.h deleted file mode 100644 --- a/src/kdatecombo.h +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************* -* kdatecombo.h -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -******************************************************************/ - -#ifndef KDATECOMBO_H -#define KDATECOMBO_H - -#include -#include - -#include - -/** - *@author Beppe Grimaldi - */ - -class KDatePicker; -class QFrame; - -class KDateCombo : public KComboBox { - Q_OBJECT - -public: - KDateCombo(QWidget *parent=0); - explicit KDateCombo(const QDate & date, QWidget *parent=0); - ~KDateCombo(); - - QDate & getDate(QDate *currentDate); - bool setDate(const QDate & newDate); - -private: - QFrame * popupFrame; - KDatePicker * datePicker; - - void initObject(const QDate & date); - - QString date2String(const QDate &); - QDate & string2Date(const QString &, QDate * ); - -protected: - bool eventFilter (QObject*, QEvent*) Q_DECL_OVERRIDE; - void mousePressEvent (QMouseEvent * e) Q_DECL_OVERRIDE; - -protected Q_SLOTS: - void dateEnteredEvent(const QDate &d=QDate()); -}; - -#endif diff --git a/src/kdatecombo.cpp b/src/kdatecombo.cpp deleted file mode 100644 --- a/src/kdatecombo.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************* -* kdatecombo.cpp -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -******************************************************************/ - -#include "kdatecombo.h" - -#include -#include -#include -//Added by qt3to4: -#include -#include - -#include -#include -#include -#include - -KDateCombo::KDateCombo(QWidget *parent) : KComboBox(parent) -{ - setEditable( false ); - - QDate date = QDate::currentDate(); - initObject(date); -} - -KDateCombo::KDateCombo(const QDate & date, QWidget *parent) : KComboBox(parent) -{ - setEditable( false ); - - initObject(date); -} - -void KDateCombo::initObject(const QDate & date) -{ - setValidator(0); - popupFrame = new QFrame(this, Qt::Popup); - popupFrame->setFrameStyle(QFrame::Box | QFrame::Raised); - popupFrame->setMidLineWidth(2); - popupFrame->installEventFilter(this); - datePicker = new KDatePicker(date, popupFrame); - datePicker->setMinimumSize(datePicker->sizeHint()); - datePicker->installEventFilter(this); - popupFrame->resize(datePicker->width() + 2 * popupFrame->frameWidth(), - datePicker->height() + 2 * popupFrame->frameWidth()); - setDate(date); - - connect(datePicker, SIGNAL(dateSelected(QDate)), this, SLOT(dateEnteredEvent(QDate))); - connect(datePicker, SIGNAL(dateEntered(QDate)), this, SLOT(dateEnteredEvent(QDate))); -} - -KDateCombo::~KDateCombo() -{ - delete datePicker; - delete popupFrame; -} - -QString KDateCombo::date2String(const QDate & date) -{ - return(KLocale::global()->formatDate(date, KLocale::ShortDate)); -} - -QDate & KDateCombo::string2Date(const QString & str, QDate *qd) -{ - return *qd = KLocale::global()->readDate(str); -} - -QDate & KDateCombo::getDate(QDate *currentDate) -{ - return string2Date(currentText(), currentDate); -} - -bool KDateCombo::setDate(const QDate & newDate) -{ - if (newDate.isValid()) - { - if (count()) - clear(); - addItem(date2String(newDate)); - return true; - } - return false; -} - -void KDateCombo::dateEnteredEvent(const QDate &newDate) -{ - QDate tempDate = newDate; - if (!tempDate.isValid()) - tempDate = datePicker->date(); - popupFrame->hide(); - setDate(tempDate); -} - -void KDateCombo::mousePressEvent (QMouseEvent * e) -{ - if (e->button() & Qt::LeftButton) - { - if (rect().contains( e->pos())) - { - QDate tempDate; - getDate(& tempDate); - datePicker->setDate(tempDate); - - // Make sure the whole popup is visible. - const QPoint pos = mapToGlobal(QPoint(0, height())); - QRect desktopGeometry = QApplication::desktop()->screenGeometry(pos); - - int x = pos.x(); - int y = pos.y(); - int w = popupFrame->width(); - int h = popupFrame->height(); - if ( x + w > desktopGeometry.x() + desktopGeometry.width() ) { - x = desktopGeometry.width() - w; - } - if ( y + h > desktopGeometry.y() + desktopGeometry.height() ) { - y = desktopGeometry.height() - h; - } - if ( x < desktopGeometry.x() ) { - x = 0; - } - if ( y < desktopGeometry.y() ) { - y = 0; - } - - // Pop the thingy up. - popupFrame->move( x, y ); - popupFrame->show(); - datePicker->setFocus(); - } - } -} - -bool KDateCombo::eventFilter (QObject*, QEvent* e) -{ - if ( e->type() == QEvent::MouseButtonPress ) - { - QMouseEvent *me = (QMouseEvent *)e; - QPoint p = mapFromGlobal( me->globalPos() ); - if (rect().contains( p ) ) - { - QTimer::singleShot(10, this, SLOT(dateEnteredEvent())); - return true; - } - } - else if ( e->type() == QEvent::KeyRelease ) - { - QKeyEvent *k = (QKeyEvent *)e; - - if (k->key()==Qt::Key_Escape) { - popupFrame->hide(); - return true; - } - else { - return false; - } - } - - return false; -} diff --git a/src/kfindtreeview.cpp b/src/kfindtreeview.cpp --- a/src/kfindtreeview.cpp +++ b/src/kfindtreeview.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/src/kftabdlg.h b/src/kftabdlg.h --- a/src/kftabdlg.h +++ b/src/kftabdlg.h @@ -34,13 +34,13 @@ class QString; class QDate; class QRegExp; +class KDateComboBox; class KDialog; class KComboBox; class KIntSpinBox; class QLabel; class KfDirDialog; -class KDateCombo; class KfindTabWidget: public KTabWidget { @@ -100,9 +100,6 @@ private: bool isDateValid(); - QString date2String(const QDate &); - QDate &string2Date(const QString &, QDate * ); - void updateDateLabels(int type, int value); QWidget *pages[3]; @@ -118,8 +115,8 @@ QLabel *andL; QButtonGroup *bg; QRadioButton *rb[2]; - KDateCombo * fromDate; - KDateCombo * toDate; + KDateComboBox * fromDate; + KDateComboBox * toDate; KIntSpinBox *timeBox; //3rd page diff --git a/src/kftabdlg.cpp b/src/kftabdlg.cpp --- a/src/kftabdlg.cpp +++ b/src/kftabdlg.cpp @@ -30,12 +30,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -46,7 +46,6 @@ #include #include -#include "kdatecombo.h" #include "kquery.h" // Static utility functions static void save_pattern(KComboBox *, const QString &, const QString &); @@ -188,11 +187,12 @@ betweenType->setCurrentIndex(1); updateDateLabels(1, 1); - QDate dt = KLocale::global()->calendar()->addYears(QDate::currentDate(), -1); + const QDate dt = QDate::currentDate().addYears(-1); - fromDate = new KDateCombo(dt, pages[1] ); + fromDate = new KDateComboBox(pages[1]); fromDate->setObjectName( QLatin1String( "fromDate" ) ); - toDate = new KDateCombo(pages[1] ); + fromDate->setDate(dt); + toDate = new KDateComboBox(pages[1] ); toDate->setObjectName( QLatin1String( "toDate" ) ); timeBox = new KIntSpinBox( pages[1] ); timeBox->setRange( 1, 60 ); @@ -582,7 +582,7 @@ void KfindTabWidget::setDefaults() { - QDate dt = KLocale::global()->calendar()->addYears(QDate::currentDate(), -1); + const QDate dt = QDate::currentDate().addYears(-1); fromDate ->setDate(dt); toDate ->setDate(QDate::currentDate()); @@ -615,16 +615,17 @@ // If we can not parse either of the dates or // "from" date is bigger than "to" date return false. - QDate hi1, hi2; + const QDate from = fromDate->date(); + const QDate to = toDate->date(); QString str; - if ( ! fromDate->getDate(&hi1).isValid() || - ! toDate->getDate(&hi2).isValid() ) - str = i18n("The date is not valid."); - else if ( hi1 > hi2 ) - str = i18n("Invalid date range."); - else if ( QDate::currentDate() < hi1 ) - str = i18n("Unable to search dates in the future."); + if (!from.isValid() || !to.isValid()) { + str = i18n("The date is not valid."); + } else if (from > to) { + str = i18n("Invalid date range."); + } else if (from > QDate::currentDate()) { + str = i18n("Unable to search dates in the future."); + } if (!str.isEmpty()) { KMessageBox::sorry(0, str); @@ -711,13 +712,12 @@ // Add date predicate if (findCreated->isChecked()) { // Modified if (rb[0]->isChecked()) { // Between dates - QDate q1, q2; - fromDate->getDate(&q1); - toDate->getDate(&q2); + const QDate &from = fromDate->date(); + const QDate &to = toDate->date(); // do not generate negative numbers .. find doesn't handle that - time_t time1 = epoch.secsTo(QDateTime(q1)); - time_t time2 = epoch.secsTo(QDateTime(q2.addDays(1))) - 1; // Include the last day + time_t time1 = epoch.secsTo(QDateTime(from)); + time_t time2 = epoch.secsTo(QDateTime(to.addDays(1))) - 1; // Include the last day query->setTimeRange(time1, time2); } @@ -792,14 +792,6 @@ binaryContextCb->isChecked(), regexpContentCb->isChecked()); } -QString KfindTabWidget::date2String(const QDate & date) { - return(KLocale::global()->formatDate(date, KLocale::ShortDate)); -} - -QDate &KfindTabWidget::string2Date(const QString & str, QDate *qd) { - return *qd = KLocale::global()->readDate(str); -} - void KfindTabWidget::getDirectory() { QString result = diff --git a/src/kquery.cpp b/src/kquery.cpp --- a/src/kquery.cpp +++ b/src/kquery.cpp @@ -29,8 +29,8 @@ #include #include #include +#include #include -#include #include #include