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

kontact

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