summaryrefslogtreecommitdiffabout
path: root/korganizer/navigatorbar.cpp
blob: 59c3e457227273f86813d6c8fb19578f3b261ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
    This file is part of KOrganizer.

    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

    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, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#include <qstring.h>
#include <qtooltip.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <q3frame.h>
#include <qlabel.h>
#include <q3popupmenu.h>
#include <qapplication.h>
#include <QDesktopWidget>
//Added by qt3to4:
#include <Q3HBoxLayout>

#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include "libkdepim/kdatepicker.h"
#include <knotifyclient.h>
#include "kdatetbl.h"

#include "koglobals.h"
#include <kglobalsettings.h>
#include "koprefs.h"
#ifndef KORG_NOPLUGINS
#include "kocore.h"
#endif

#include <kcalendarsystem.h>

#include "navigatorbar.h"

NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name )
  : QWidget( parent, name )
{
  Q3BoxLayout *topLayout = new Q3HBoxLayout( this );

  // Set up the control buttons and date label
  mCtrlFrame = new Q3Frame( this );
  mCtrlFrame->setFrameStyle(Q3Frame::Panel|Q3Frame::Raised);
  mCtrlFrame->setLineWidth(1);

  topLayout->addWidget( mCtrlFrame );

 

  bool isRTL = KOGlobals::self()->reverseLayout();
#ifndef DESKTOP_VERSION
  bool isDesktop = false;
#else
  bool isDesktop = true;
#endif
  if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 )
      isDesktop = true;
  // Create backward navigation buttons
  mPrevYear = new QPushButton( mCtrlFrame );
  mPrevYear->setPixmap( SmallIcon( isDesktop ? "3leftarrowB" : "3leftarrow" ) );
  QToolTip::add( mPrevYear, i18n("Previous Year") );

  mPrevMonth = new QPushButton( mCtrlFrame );
  mPrevMonth->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow") );
  QToolTip::add( mPrevMonth, i18n("Previous Month") );

  // Create forward navigation buttons
  mNextMonth = new QPushButton( mCtrlFrame );
  mNextMonth->setPixmap( SmallIcon( isDesktop ? "2rightarrowB" : "2rightarrow") );
  QToolTip::add( mNextMonth, i18n("Next Month") );

  mPrevWeek = new QPushButton( mCtrlFrame );
  mPrevWeek->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") );
  QToolTip::add( mPrevWeek, i18n("Previous Week") );

  // Create forward navigation buttons
  mNextWeek = new QPushButton( mCtrlFrame );
  mNextWeek->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") );
  QToolTip::add( mNextWeek, i18n("Next Week") );

  mNextYear = new QPushButton( mCtrlFrame );
  mNextYear->setPixmap( SmallIcon( isDesktop ? "3rightarrowB": "3rightarrow") );
  QToolTip::add( mNextYear, i18n("Next Year") );
  mSelectMonth = new QPushButton( mCtrlFrame );
  // Create month name label
  //selectMonth->setFont( tfont );
  // selectMonth->setAlignment( AlignCenter );
  //mDateLabel = new QLabel( selectMonth );
  //mDateLabel->setFont( tfont );
  //mDateLabel->setAlignment( AlignCenter );
  if ( QString ( name ) == QString("useBigPixmaps") ) {
      mNextMonth->setFlat( true);
      mNextWeek->setFlat( true);
      mNextYear->setFlat( true);
      mSelectMonth->setFlat( true);
      mPrevYear->setFlat( true);
      mPrevMonth->setFlat( true);
      mPrevWeek->setFlat( true);

      mPrevYear->setAutoRepeat( true );
      mPrevMonth->setAutoRepeat( true );
      mNextMonth->setAutoRepeat( true );
      mPrevWeek->setAutoRepeat( true );
      mNextWeek->setAutoRepeat( true );
      mNextYear->setAutoRepeat( true );
  } else {
      mPrevWeek->hide();
      mNextWeek->hide();
  }

  resetFont( font() );

  
  // set up control frame layout
  Q3BoxLayout *ctrlLayout = new Q3HBoxLayout( mCtrlFrame, 1 );
  ctrlLayout->addWidget( mPrevYear, 3 );
  ctrlLayout->addWidget( mPrevMonth, 3 );
  ctrlLayout->addWidget( mPrevWeek, 3 );
  //ctrlLayout->addStretch( 1 );
  // ctrlLayout->addSpacing( 1 );
  // ctrlLayout->addWidget( mDateLabel );
  ctrlLayout->addWidget( mSelectMonth );
  //  ctrlLayout->addSpacing( 1 );
  // ctrlLayout->addStretch( 1 );
  ctrlLayout->addWidget( mNextWeek, 3 );
  ctrlLayout->addWidget( mNextMonth, 3 );
  ctrlLayout->addWidget( mNextYear, 3 );

  connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
  connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
  connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
  connect( mPrevWeek, SIGNAL( clicked() ), SIGNAL( goPrevWeek() ) );
  connect( mNextWeek, SIGNAL( clicked() ), SIGNAL( goNextWeek() ) );
  connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
  connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) );
  mPrevYear->setFocusPolicy(Qt::NoFocus);
  mPrevMonth->setFocusPolicy(Qt::NoFocus);
  mNextMonth->setFocusPolicy(Qt::NoFocus);
  mPrevWeek->setFocusPolicy(Qt::NoFocus);
  mNextWeek->setFocusPolicy(Qt::NoFocus);
  mNextYear->setFocusPolicy(Qt::NoFocus);
  mSelectMonth->setFocusPolicy(Qt::NoFocus);
  setSizePolicy( QSizePolicy (  QSizePolicy::Expanding ,QSizePolicy::Fixed ) );
   
}

NavigatorBar::~NavigatorBar()
{
}
QSize NavigatorBar::sizeHint() const
{
    int wid = mCurrentMinWid ;
    if ( mPrevYear->isVisible() )
        wid += mCurrentButtonMinWid;
    if ( mPrevMonth->isVisible() )
        wid += mCurrentButtonMinWid;
    if ( mPrevWeek->isVisible() )
        wid += mCurrentButtonMinWid;
    if ( mNextMonth->isVisible() )
        wid += mCurrentButtonMinWid;
    if ( mNextWeek->isVisible() )
        wid += mCurrentButtonMinWid;
    if ( mNextYear->isVisible() )
        wid += mCurrentButtonMinWid;
    //qDebug("ret %d %d ", wid, mCurrentHei);
  return   QSize ( wid, mCurrentHei );
}
QSize NavigatorBar::sizeHintTwoButtons( int butNum ) const
{
    return   QSize ( mCurrentMinWid  + butNum * mCurrentButtonMinWid , mCurrentHei );
}
void NavigatorBar::resetFont ( QFont fo )
{

 QFont tfont = fo;
 if ( QApplication::desktop()->width() >= 480 )
     tfont.setPointSize(tfont.pointSize()+2);
 tfont.setBold(true);

 mSelectMonth->setFont( tfont );
  // Set minimum width to width of widest month name label
  int i;
  int maxwidth = 0;
  QFontMetrics fm ( mSelectMonth->font() );
  int width = fm.width("September '00" );
  maxwidth = width+2;
  int size = fm.height()+2;
  if ( QApplication::desktop()->width() >= 480 ) { 
      size += 6;
      maxwidth+= 6;
  }
  mSelectMonth->setMinimumWidth( maxwidth );
  mSelectMonth->setFixedHeight( size );
  mPrevYear->setFixedHeight(  size );
  mPrevMonth->setFixedHeight( size );
  mPrevWeek->setFixedHeight( size );
  mNextMonth->setFixedHeight( size );
  mNextWeek->setFixedHeight( size );
  mNextYear->setFixedHeight ( size );
  mCurrentHei = size +2;
  mCurrentMinWid =  maxwidth+2;
  mCurrentButtonMinWid = mPrevYear->sizeHint().width();
}
  
void NavigatorBar::showButtons( bool left, bool right )
{
  if ( left ) {
    mPrevYear->show();
    mPrevMonth->show();
  } else {
    mPrevYear->hide();
    mPrevMonth->hide();
  }

  if ( right ) {
    mNextYear->show();
    mNextMonth->show();
  } else {
    mNextYear->hide();
    mNextMonth->hide();
  }
  if ( !left && !right ) {
      //mSelectMonth->setMaximumWidth( 1024 );
      mSelectMonth->setSizePolicy( QSizePolicy (  QSizePolicy::Expanding ,QSizePolicy::Fixed ) );
  }
}

void NavigatorBar::selectMonth()
{

    int month;
  KPopupFrame* popup = new KPopupFrame(this);
  KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
  // -----
  picker->resize(picker->sizeHint());
  popup->setMainWidget(picker);
  picker->setFocus();
  connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
  if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height()))))
    {
        month = picker->getResult();
        emit monthSelected ( month );
    } else {
      KNotifyClient::beep();
    }
  delete popup;
}
void NavigatorBar::selectDates( const KCal::DateList &dateList )
{
  if (dateList.count() > 0) {
    QDate date = dateList.first();

    const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();

    // compute the label at the top of the navigator
    QString dtstr = calSys->monthName( date ) + " '" +
                    QString::number( calSys->year( date ) ).right(2);

    mSelectMonth->setText( dtstr );
  }
}