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

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • print
knoteprintselectednotesdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "knoteprintselectednotesdialog.h"
19 #include "knotes/print/knoteprintselectthemecombobox.h"
20 #include "knoteprintobject.h"
21 #include "notes/knote.h"
22 
23 #include <KLocalizedString>
24 #include <KConfigGroup>
25 
26 #include <QListWidget>
27 #include <QHBoxLayout>
28 #include <QLabel>
29 
30 KNotePrintSelectedNotesDialog::KNotePrintSelectedNotesDialog(QWidget *parent)
31  : KDialog(parent),
32  mPreview(false)
33 {
34  setCaption( i18n( "Select notes" ) );
35  setButtons( User1 | Ok | Cancel );
36  QWidget *w = new QWidget;
37  QVBoxLayout *vbox = new QVBoxLayout;
38  w->setLayout(vbox);
39 
40  mListNotes = new QListWidget;
41  mListNotes->setSelectionMode(QAbstractItemView::ExtendedSelection);
42  vbox->addWidget(mListNotes);
43 
44  QHBoxLayout *lay = new QHBoxLayout;
45  lay->setMargin(0);
46  vbox->addLayout(lay);
47  QLabel *lab = new QLabel(i18n("Printing theme:"));
48  lay->addWidget(lab);
49  mTheme = new KNotePrintSelectThemeComboBox;
50  mTheme->loadThemes();
51  lay->addWidget(mTheme);
52 
53  setButtonIcon(User1, KIcon(QLatin1String("document-print-preview")));
54  setButtonText(User1, i18n("Preview"));
55  setButtonIcon(Ok, KIcon(QLatin1String("document-print")));
56  setButtonText(Ok, i18n("Print"));
57  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotPreview()));
58  connect(mListNotes, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
59  setMainWidget(w);
60  readConfig();
61  slotSelectionChanged();
62 }
63 
64 KNotePrintSelectedNotesDialog::~KNotePrintSelectedNotesDialog()
65 {
66  writeConfig();
67 }
68 
69 void KNotePrintSelectedNotesDialog::slotSelectionChanged()
70 {
71  const bool hasSelection = (mListNotes->selectedItems().count() > 0);
72  enableButton(User1, hasSelection);
73  enableButtonOk(hasSelection);
74 }
75 
76 void KNotePrintSelectedNotesDialog::setNotes(const QHash<Akonadi::Item::Id, KNote*> &notes)
77 {
78  mNotes = notes;
79  QHashIterator<Akonadi::Item::Id, KNote *> i(notes);
80  while (i.hasNext()) {
81  i.next();
82  QListWidgetItem *item =new QListWidgetItem(mListNotes);
83  item->setText(i.value()->name());
84  item->setToolTip(i.value()->text());
85  item->setData(AkonadiId, i.key());
86  }
87 }
88 
89 QList<KNotePrintObject *> KNotePrintSelectedNotesDialog::selectedNotes() const
90 {
91  QList<KNotePrintObject *> lstPrintObj;
92  QList<QListWidgetItem *> lst = mListNotes->selectedItems ();
93  Q_FOREACH(QListWidgetItem *item, lst) {
94  Akonadi::Item::Id akonadiId = item->data(AkonadiId).toLongLong();
95  if (akonadiId != -1) {
96  KNotePrintObject *obj = new KNotePrintObject(mNotes.value(akonadiId)->item());
97  lstPrintObj.append(obj);
98  }
99  }
100  return lstPrintObj;
101 }
102 
103 QString KNotePrintSelectedNotesDialog::selectedTheme() const
104 {
105  return mTheme->selectedTheme();
106 }
107 
108 bool KNotePrintSelectedNotesDialog::preview() const
109 {
110  return mPreview;
111 }
112 
113 void KNotePrintSelectedNotesDialog::readConfig()
114 {
115  KConfigGroup grp( KGlobal::config(), "KNotePrintSelectedNotesDialog" );
116  const QSize size = grp.readEntry( "Size", QSize(300, 200) );
117  if ( size.isValid() ) {
118  resize( size );
119  }
120 }
121 
122 void KNotePrintSelectedNotesDialog::writeConfig()
123 {
124  KConfigGroup grp( KGlobal::config(), "KNotePrintSelectedNotesDialog" );
125  grp.writeEntry( "Size", size() );
126  grp.sync();
127 }
128 
129 void KNotePrintSelectedNotesDialog::slotPreview()
130 {
131  mPreview = true;
132  accept();
133 }
134 
QVariant::toLongLong
qlonglong toLongLong(bool *ok) const
QWidget
KNotePrintSelectThemeComboBox::selectedTheme
QString selectedTheme() const
Definition: knoteprintselectthemecombobox.cpp:85
QSize::isValid
bool isValid() const
KNotePrintSelectedNotesDialog::setNotes
void setNotes(const QHash< Akonadi::Item::Id, KNote * > &notes)
Definition: knoteprintselectednotesdialog.cpp:76
KNotePrintObject
Definition: knoteprintobject.h:27
QAbstractItemView::setSelectionMode
void setSelectionMode(QAbstractItemView::SelectionMode mode)
KNotePrintSelectedNotesDialog::preview
bool preview() const
Definition: knoteprintselectednotesdialog.cpp:108
QHashIterator::key
const Key & key() const
KNotePrintSelectedNotesDialog::KNotePrintSelectedNotesDialog
KNotePrintSelectedNotesDialog(QWidget *parent=0)
Definition: knoteprintselectednotesdialog.cpp:30
QHashIterator::hasNext
bool hasNext() const
QListWidgetItem
QHBoxLayout
KDialog
QListWidget
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
knote.h
KNotePrintSelectThemeComboBox::loadThemes
void loadThemes()
Definition: knoteprintselectthemecombobox.cpp:38
QList::append
void append(const T &value)
QWidget::setLayout
void setLayout(QLayout *layout)
knoteprintselectthemecombobox.h
knoteprintobject.h
QHash< Akonadi::Item::Id, KNote * >
KNotePrintSelectThemeComboBox
Definition: knoteprintselectthemecombobox.h:24
QListWidgetItem::setToolTip
void setToolTip(const QString &toolTip)
QHashIterator
knoteprintselectednotesdialog.h
KNotePrintSelectedNotesDialog::~KNotePrintSelectedNotesDialog
~KNotePrintSelectedNotesDialog()
Definition: knoteprintselectednotesdialog.cpp:64
QListWidgetItem::data
virtual QVariant data(int role) const
QVBoxLayout
KNotePrintSelectedNotesDialog::selectedNotes
QList< KNotePrintObject * > selectedNotes() const
Definition: knoteprintselectednotesdialog.cpp:89
QString
QList
QLayout::setMargin
void setMargin(int margin)
QHash::value
const T value(const Key &key) const
QHashIterator::next
Item next()
QListWidget::selectedItems
QList< QListWidgetItem * > selectedItems() const
QSize
QListWidgetItem::setData
virtual void setData(int role, const QVariant &value)
KNotePrintSelectedNotesDialog::selectedTheme
QString selectedTheme() const
Definition: knoteprintselectednotesdialog.cpp:103
QLatin1String
QHashIterator::value
const T & value() const
QLabel
QListWidgetItem::setText
void setText(const QString &text)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

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

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
  • pimprint

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