~ubuntu-branches/ubuntu/wily/knemo/wily

« back to all changes in this revision

Viewing changes to src/kcm/kdatepickerpopup.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-11-05 21:57:32 UTC
  • mfrom: (1.2.2) (23 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20121105215732-81tfpooc7ynxy0r9
Tags: 0.7.4-2
Add Build-Depends: kde-workspace-dev - fixes FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of libkdepim.
 
3
 
 
4
  Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
 
5
 
 
6
  This library is free software; you can redistribute it and/or
 
7
  modify it under the terms of the GNU Library General Public
 
8
  License as published by the Free Software Foundation; either
 
9
  version 2 of the License, or (at your option) any later version.
 
10
 
 
11
  This library is distributed in the hope that it will be useful,
 
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
  Library General Public 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
 
18
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
  Boston, MA 02110-1301, USA.
 
20
*/
 
21
 
 
22
#include "kdatepickerpopup.h"
 
23
 
 
24
#include <KDatePicker>
 
25
#include <KLocale>
 
26
 
 
27
#include <QtCore/QDateTime>
 
28
#include <QtGui/QWidgetAction>
 
29
 
 
30
class KDatePickerAction : public QWidgetAction
 
31
{
 
32
  public:
 
33
    KDatePickerAction( KDatePicker *widget, QObject *parent )
 
34
      : QWidgetAction( parent ),
 
35
        mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
 
36
    {
 
37
    }
 
38
 
 
39
  protected:
 
40
    QWidget *createWidget( QWidget *parent )
 
41
    {
 
42
      mDatePicker->setParent( parent );
 
43
      return mDatePicker;
 
44
    }
 
45
 
 
46
    void deleteWidget( QWidget *widget )
 
47
    {
 
48
      if ( widget != mDatePicker ) {
 
49
        return;
 
50
      }
 
51
 
 
52
      mDatePicker->setParent( mOriginalParent );
 
53
    }
 
54
 
 
55
  private:
 
56
    KDatePicker *mDatePicker;
 
57
    QWidget *mOriginalParent;
 
58
};
 
59
 
 
60
KDatePickerPopup::KDatePickerPopup( Items items, const QDate &date, QWidget *parent )
 
61
  : QMenu( parent )
 
62
{
 
63
  mItems = items;
 
64
 
 
65
  mDatePicker = new KDatePicker( this );
 
66
  mDatePicker->setCloseButton( false );
 
67
 
 
68
  connect( mDatePicker, SIGNAL( dateEntered( const QDate& ) ),
 
69
           SLOT( slotDateChanged( const QDate& ) ) );
 
70
  connect( mDatePicker, SIGNAL( dateSelected( const QDate& ) ),
 
71
           SLOT( slotDateChanged( const QDate& ) ) );
 
72
 
 
73
  mDatePicker->setDate( date );
 
74
 
 
75
  buildMenu();
 
76
}
 
77
 
 
78
void KDatePickerPopup::buildMenu()
 
79
{
 
80
  if ( isVisible() ) {
 
81
    return;
 
82
  }
 
83
  clear();
 
84
 
 
85
  if ( mItems & DatePicker ) {
 
86
    addAction( new KDatePickerAction( mDatePicker, this ) );
 
87
 
 
88
    if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
 
89
      addSeparator();
 
90
    }
 
91
  }
 
92
 
 
93
  if ( mItems & Words ) {
 
94
    addAction( i18nc( "@option today", "&Today" ), this, SLOT( slotToday() ) );
 
95
    addAction( i18nc( "@option tomorrow", "To&morrow" ), this, SLOT( slotTomorrow() ) );
 
96
    addAction( i18nc( "@option next week", "Next &Week" ), this, SLOT( slotNextWeek() ) );
 
97
    addAction( i18nc( "@option next month", "Next M&onth" ), this, SLOT( slotNextMonth() ) );
 
98
 
 
99
    if ( mItems & NoDate ) {
 
100
      addSeparator();
 
101
    }
 
102
  }
 
103
 
 
104
  if ( mItems & NoDate ) {
 
105
    addAction( i18nc( "@option do not specify a date", "No Date" ), this, SLOT( slotNoDate() ) );
 
106
  }
 
107
}
 
108
 
 
109
KDatePicker *KDatePickerPopup::datePicker() const
 
110
{
 
111
  return mDatePicker;
 
112
}
 
113
 
 
114
void KDatePickerPopup::setDate( const QDate &date )
 
115
{
 
116
  mDatePicker->setDate( date );
 
117
}
 
118
 
 
119
#if 0
 
120
void KDatePickerPopup::setItems( int items )
 
121
{
 
122
  mItems = items;
 
123
  buildMenu();
 
124
}
 
125
#endif
 
126
 
 
127
void KDatePickerPopup::slotDateChanged( const QDate &date )
 
128
{
 
129
  emit dateChanged( date );
 
130
  hide();
 
131
}
 
132
 
 
133
void KDatePickerPopup::slotToday()
 
134
{
 
135
  emit dateChanged( QDate::currentDate() );
 
136
}
 
137
 
 
138
void KDatePickerPopup::slotTomorrow()
 
139
{
 
140
  emit dateChanged( QDate::currentDate().addDays( 1 ) );
 
141
}
 
142
 
 
143
void KDatePickerPopup::slotNoDate()
 
144
{
 
145
  emit dateChanged( QDate() );
 
146
}
 
147
 
 
148
void KDatePickerPopup::slotNextWeek()
 
149
{
 
150
  emit dateChanged( QDate::currentDate().addDays( 7 ) );
 
151
}
 
152
 
 
153
void KDatePickerPopup::slotNextMonth()
 
154
{
 
155
  emit dateChanged( QDate::currentDate().addMonths( 1 ) );
 
156
}
 
157
 
 
158
#include "kdatepickerpopup.moc"