• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
  • editor
dateeditwidget.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "dateeditwidget.h"
23
24#include "kdatepickerpopup_p.h"
25
26#include <kdatepicker.h>
27#include <kglobal.h>
28#include <kicon.h>
29#include <klocalizedstring.h>
30
31#include <QContextMenuEvent>
32#include <QHBoxLayout>
33#include <QLabel>
34#include <QToolButton>
35
36DateView::DateView(QWidget *parent)
37 : QLabel(parent)
38{
39 setTextInteractionFlags(Qt::TextSelectableByMouse);
40 setFrameShape(QFrame::StyledPanel);
41 setFrameShadow(QFrame::Sunken);
42}
43
44void DateView::contextMenuEvent(QContextMenuEvent *event)
45{
46 if (text().isEmpty()) {
47 return;
48 }
49
50 QMenu menu;
51 menu.addAction(i18n("Remove"), this, SLOT(emitSignal()));
52
53 menu.exec(event->globalPos());
54}
55
56void DateView::emitSignal()
57{
58 emit resetDate();
59}
60
61DateEditWidget::DateEditWidget(Type type, QWidget *parent)
62 : QWidget(parent)
63 , mReadOnly(false)
64{
65 QHBoxLayout *layout = new QHBoxLayout(this);
66 layout->setMargin(0);
67
68 mView = new DateView;
69 layout->addWidget(mView);
70
71 mClearButton = new QToolButton;
72 if (layoutDirection() == Qt::LeftToRight) {
73 mClearButton->setIcon(KIcon(QLatin1String("edit-clear-locationbar-rtl")));
74 } else {
75 mClearButton->setIcon(KIcon(QLatin1String("edit-clear-locationbar-ltr")));
76 }
77 layout->addWidget(mClearButton);
78
79 mSelectButton = new QToolButton;
80 mSelectButton->setPopupMode(QToolButton::InstantPopup);
81 switch (type) {
82 case General:
83 mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-day")));
84 break;
85 case Birthday:
86 mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-birthday")));
87 break;
88 case Anniversary:
89 mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-wedding-anniversary")));
90 break;
91 }
92
93 layout->addWidget(mSelectButton);
94 setFocusProxy(mSelectButton);
95 setFocusPolicy(Qt::StrongFocus);
96
97 mMenu = new KDatePickerPopup(KDatePickerPopup::DatePicker, QDate(), this);
98 mSelectButton->setMenu(mMenu);
99
100 connect(mClearButton, SIGNAL(clicked()), SLOT(resetDate()));
101 connect(mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)));
102 connect(mView, SIGNAL(resetDate()), SLOT(resetDate()));
103
104 updateView();
105}
106
107DateEditWidget::~DateEditWidget()
108{
109}
110
111void DateEditWidget::setDate(const QDate &date)
112{
113 mDate = date;
114 mMenu->setDate(mDate);
115 updateView();
116}
117
118QDate DateEditWidget::date() const
119{
120 return mDate;
121}
122
123void DateEditWidget::setReadOnly(bool readOnly)
124{
125 mReadOnly = readOnly;
126
127 mSelectButton->setEnabled(!readOnly);
128 mClearButton->setEnabled(!readOnly);
129}
130
131void DateEditWidget::dateSelected(const QDate &date)
132{
133 mDate = date;
134 updateView();
135}
136
137void DateEditWidget::resetDate()
138{
139 mDate = QDate();
140 updateView();
141}
142
143void DateEditWidget::updateView()
144{
145 if (mDate.isValid()) {
146 mView->setText(KGlobal::locale()->formatDate(mDate));
147 mClearButton->show();
148 } else {
149 mView->setText(QString());
150 mClearButton->hide();
151 }
152}
KDatePickerPopup
This menu helps the user to select a date quickly.
Definition kdatepickerpopup_p.h:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal