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

kontact

  • sources
  • kde-4.12
  • kdepim
  • kontact
  • plugins
  • knotes
knoteseditdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 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 "knoteseditdialog.h"
19 #include "knotes/knoteedit.h"
20 
21 #include <KCal/Journal>
22 using namespace KCal;
23 
24 #include <KActionCollection>
25 #include <KComponentData>
26 #include <KDialog>
27 #include <KLocale>
28 #include <KToolBar>
29 #include <KLineEdit>
30 
31 #include <KXMLGUIBuilder>
32 #include <KXMLGUIFactory>
33 
34 #include <QAction>
35 #include <QHBoxLayout>
36 #include <QLabel>
37 #include <QVBoxLayout>
38 #include <QDebug>
39 
40 
41 KNoteEditDialog::KNoteEditDialog(bool readOnly, QWidget *parent)
42  : KDialog(parent)
43 {
44  init(readOnly);
45 }
46 
47 void KNoteEditDialog::init(bool readOnly)
48 {
49  setCaption( readOnly ? i18nc( "@title:window", "Show Popup Note" ) : i18nc( "@title:window", "Edit Popup Note" ) );
50  setButtons( readOnly ? Close : Ok | Cancel );
51  setDefaultButton( readOnly ? Close : Ok );
52  setModal( true );
53  showButtonSeparator( true );
54  // this dialog is modal to prevent one from editing the same note twice
55  // in two different windows
56 
57  setComponentData( KComponentData( "knotes" ) ); // TODO: memleak
58  setXMLFile( QLatin1String("knotesui.rc") );
59 
60  QWidget *page = new QWidget( this );
61  setMainWidget( page );
62  QVBoxLayout *layout = new QVBoxLayout( page );
63 
64  QHBoxLayout *hbl = new QHBoxLayout();
65  layout->addItem( hbl );
66  hbl->setSpacing( marginHint() );
67  QLabel *label = new QLabel( page );
68  label->setText( i18nc( "@label popup note name", "Name:" ) );
69  hbl->addWidget( label, 0 );
70  mTitleEdit= new KLineEdit( page );
71  mTitleEdit->setObjectName( QLatin1String("name") );
72  if (!readOnly)
73  connect(mTitleEdit, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
74  hbl->addWidget( mTitleEdit, 1, Qt::AlignVCenter );
75 
76  //TODO customize it
77  mNoteEdit = new KNoteEdit( QLatin1String("knotesrc"), actionCollection(), page );
78  mNoteEdit->setFocus();
79 
80  KXMLGUIBuilder builder( page );
81  KXMLGUIFactory factory( &builder, this );
82  factory.addClient( this );
83 
84  mTool = static_cast<KToolBar *>( factory.container( QLatin1String("note_tool"), this ) );
85  layout->addWidget( mTool );
86  layout->addWidget( mNoteEdit );
87 
88  actionCollection()->addAssociatedWidget( this );
89  foreach ( QAction *action, actionCollection()->actions() ) {
90  action->setShortcutContext( Qt::WidgetWithChildrenShortcut );
91  }
92  readConfig();
93  setReadOnly(readOnly);
94 }
95 
96 KNoteEditDialog::~KNoteEditDialog()
97 {
98  writeConfig();
99 }
100 
101 void KNoteEditDialog::setAcceptRichText(bool b)
102 {
103  mNoteEdit->setAcceptRichText( b );
104  mTool->setVisible(b);
105 }
106 
107 void KNoteEditDialog::setReadOnly(bool b)
108 {
109  mNoteEdit->setEnabled( !b );
110  mTool->setEnabled(!b);
111  mTitleEdit->setEnabled(!b);
112 }
113 
114 void KNoteEditDialog::readConfig()
115 {
116  KConfigGroup grp( KGlobal::config(), "KNoteEditDialog" );
117  const QSize size = grp.readEntry( "Size", QSize(300, 200) );
118  if ( size.isValid() ) {
119  resize( size );
120  }
121 }
122 
123 void KNoteEditDialog::writeConfig()
124 {
125  KConfigGroup grp( KGlobal::config(), "KNoteEditDialog" );
126  grp.writeEntry( "Size", size() );
127  grp.sync();
128 }
129 
130 QString KNoteEditDialog::text() const
131 {
132  return mNoteEdit->text();
133 }
134 
135 void KNoteEditDialog::setText( const QString &text )
136 {
137  mNoteEdit->setText( text );
138 }
139 
140 QString KNoteEditDialog::title() const
141 {
142  return mTitleEdit->text();
143 }
144 
145 void KNoteEditDialog::setTitle( const QString &text )
146 {
147  mTitleEdit->setText( text );
148  if (mTitleEdit->isEnabled())
149  enableButtonOk(!text.isEmpty());
150 }
151 
152 KNoteEdit *KNoteEditDialog::noteEdit() const
153 {
154  return mNoteEdit;
155 }
156 
157 void KNoteEditDialog::slotTextChanged(const QString &text)
158 {
159  enableButtonOk(!text.isEmpty());
160 }
161 
162 void KNoteEditDialog::setTabSize(int size)
163 {
164  mNoteEdit->setTabStop(size);
165 }
166 
167 void KNoteEditDialog::setAutoIndentMode( bool newmode )
168 {
169  mNoteEdit->setAutoIndentMode(newmode);
170 }
171 
172 void KNoteEditDialog::setTextFont( const QFont &font )
173 {
174  mNoteEdit->setTextFont(font);
175 }
176 
177 #include "knoteseditdialog.moc"
178 
KNoteEditDialog::setTabSize
void setTabSize(int size)
Definition: knoteseditdialog.cpp:162
KNoteEditDialog::setReadOnly
void setReadOnly(bool b)
Definition: knoteseditdialog.cpp:107
text
virtual QByteArray text(quint32 serialNumber) const =0
KNoteEditDialog::title
QString title() const
Definition: knoteseditdialog.cpp:140
QWidget
KDialog
KNoteEditDialog::text
QString text() const
Definition: knoteseditdialog.cpp:130
KNoteEditDialog::setAutoIndentMode
void setAutoIndentMode(bool newmode)
Definition: knoteseditdialog.cpp:167
KNoteEditDialog::setTitle
void setTitle(const QString &text)
Definition: knoteseditdialog.cpp:145
KNoteEditDialog::~KNoteEditDialog
~KNoteEditDialog()
Definition: knoteseditdialog.cpp:96
KNoteEditDialog::setText
void setText(const QString &text)
Definition: knoteseditdialog.cpp:135
KLineEdit
QLabel
knoteseditdialog.h
KNoteEditDialog::setTextFont
void setTextFont(const QFont &font)
Definition: knoteseditdialog.cpp:172
KNoteEditDialog::KNoteEditDialog
KNoteEditDialog(bool readOnly, QWidget *parent=0)
Definition: knoteseditdialog.cpp:41
KNoteEditDialog::noteEdit
KNoteEdit * noteEdit() const
Definition: knoteseditdialog.cpp:152
KNoteEditDialog::setAcceptRichText
void setAcceptRichText(bool b)
Definition: knoteseditdialog.cpp:101
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • 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

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