• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • widgets
kweekdaycheckcombo.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
3  Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org>
4  Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
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 "kweekdaycheckcombo.h"
23 
24 #include <KGlobal>
25 #include <KLocale>
26 #include <KCalendarSystem>
27 #include <KDebug>
28 
29 using namespace KPIM;
30 
31 KWeekdayCheckCombo::KWeekdayCheckCombo(QWidget* parent,bool first5Checked ): KCheckComboBox( parent )
32 {
33  const KCalendarSystem *calSys = KGlobal::locale()->calendar();
34  const int weekStart = KGlobal::locale()->weekStartDay();
35  QStringList checkedItems;
36  for ( int i = 0; i < 7; ++i ) {
37  // i is the nr of the combobox, not the day of week!
38  const int dayOfWeek = ( i + weekStart + 6 ) % 7;
39 
40  const QString weekDayName = calSys->weekDayName( dayOfWeek + 1, KCalendarSystem::ShortDayName );
41  addItem( weekDayName );
42  // by default Monday - Friday should be checked
43  // which corresponds to index 0 - 4;
44  if ( first5Checked && dayOfWeek < 5 ) {
45  checkedItems << weekDayName;
46  }
47  }
48  if ( first5Checked ) {
49  setCheckedItems( checkedItems );
50  }
51 }
52 
53 
54 KWeekdayCheckCombo::~KWeekdayCheckCombo()
55 {
56 }
57 
58 QBitArray KWeekdayCheckCombo::days() const
59 {
60  QBitArray days( 7 );
61  const int weekStart = KGlobal::locale()->weekStartDay();
62 
63  for ( int i = 0; i < 7; ++i ) {
64  // i is the nr of the combobox, not the day of week!
65  const int index = ( 1 + i + ( 7 - weekStart ) ) % 7;
66  days.setBit( i, itemCheckState( index ) == Qt::Checked );
67  }
68 
69  return days;
70 }
71 
72 int KWeekdayCheckCombo::weekdayIndex( const QDate &date ) const
73 {
74  if ( !date.isValid() )
75  return -1;
76  const int weekStart = KGlobal::locale()->weekStartDay();
77  const KCalendarSystem *calSys = KGlobal::locale()->calendar();
78  const int dayOfWeek = calSys->dayOfWeek( date ) - 1; // Values 1 - 7, we need 0 - 6
79 
80  // kDebug() << "dayOfWeek = " << dayOfWeek << " weekStart = " << weekStart
81  // << "; result " << ( ( dayOfWeek + weekStart ) % 7 ) << "; date = " << date;
82  return ( 1 + dayOfWeek + ( 7 - weekStart ) ) % 7;
83 }
84 
85 void KWeekdayCheckCombo::setDays( const QBitArray &days, const QBitArray &disableDays )
86 {
87  Q_ASSERT( count() == 7 ); // The combobox must be filled.
88 
89  QStringList checkedDays;
90  const int weekStart = KGlobal::locale()->weekStartDay();
91  for ( int i = 0; i < 7; ++i ) {
92  // i is the nr of the combobox, not the day of week!
93  const int index = ( 1 + i + ( 7 - weekStart ) ) % 7;
94 
95  // kDebug() << "Checking for i = " << i << "; index = " << index << days.testBit( i );
96  // kDebug() << "Disabling? for i = " << i << "; index = " << index << !disableDays.testBit( i );
97 
98  if ( days.testBit( i ) ) {
99  checkedDays << itemText( index );
100  }
101  if( !disableDays.isEmpty() ) {
102  setItemEnabled( index, !disableDays.testBit( i ) );
103  }
104  }
105  setCheckedItems( checkedDays );
106 }
107 
108 
109 
110 #include "kweekdaycheckcombo.moc"
KPIM::KCheckComboBox::checkedItems
QStringList checkedItems
Definition: kcheckcombobox.h:49
kweekdaycheckcombo.h
QWidget
KPIM::KCheckComboBox
A combobox that shows its items in such a way that they can be checked in the drop menu...
Definition: kcheckcombobox.h:42
KPIM::KWeekdayCheckCombo::weekdayIndex
int weekdayIndex(const QDate &date) const
Returns the index of the weekday represented by the QDate object.
Definition: kweekdaycheckcombo.cpp:72
KPIM::KCheckComboBox::setItemEnabled
void setItemEnabled(int index, bool enabled=true)
Set the item at.
Definition: kcheckcombobox.cpp:253
KPIM::KWeekdayCheckCombo::~KWeekdayCheckCombo
virtual ~KWeekdayCheckCombo()
Definition: kweekdaycheckcombo.cpp:54
KPIM::KWeekdayCheckCombo::days
QBitArray days() const
Retrieve the checked days.
Definition: kweekdaycheckcombo.cpp:58
KPIM::KWeekdayCheckCombo::setDays
void setDays(const QBitArray &days, const QBitArray &disableDays=QBitArray())
Set the checked days on this combobox.
Definition: kweekdaycheckcombo.cpp:85
KPIM::KCheckComboBox::itemCheckState
Qt::CheckState itemCheckState(int index) const
Returns the check state of item at given index.
Definition: kcheckcombobox.cpp:180
KPIM::KCheckComboBox::setCheckedItems
void setCheckedItems(const QStringList &items, int role=Qt::DisplayRole)
Sets the currently selected items.
Definition: kcheckcombobox.cpp:204
KPIM::KWeekdayCheckCombo::KWeekdayCheckCombo
KWeekdayCheckCombo(QWidget *parent=0, bool first5Checked=false)
Definition: kweekdaycheckcombo.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



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