KProperty

symbolcombo.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 
21 #include "symbolcombo.h"
22 
23 #include <QLineEdit>
24 #include <QPushButton>
25 #include <QPainter>
26 #include <QVariant>
27 #include <QHBoxLayout>
28 
29 class Q_DECL_HIDDEN KPropertySymbolComboEditor::Private
30 {
31 public:
32  Private() {
33  }
34  QLineEdit *edit;
35  QPushButton *select;
36 };
37 
38 KPropertySymbolComboEditor::KPropertySymbolComboEditor(KProperty *property, QWidget *parent)
39  : Widget(property, parent), d(new Private)
40 {
41  setHasBorders(false);
42  QHBoxLayout *l = new QHBoxLayout(this);
43 
44  d->edit = new QLineEdit(this);
45  d->edit->setReadOnly(true);
46  d->edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
47  d->edit->setMinimumHeight(5);
48  d->edit->setMaxLength(1);
49  l->addWidget(d->edit);
50  d->select = new QPushButton(this);
51  Utils::setupDotDotDotButton(d->select, tr("Select symbol"),
52  tr("Selects a symbol"));
53  d->select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
54  d->select->setMinimumHeight(5);
55  l->addWidget(d->select);
56 
57  connect(d->select, SIGNAL(clicked()), this, SLOT(selectChar()));
58  connect(d->edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
59 }
60 
61 KPropertySymbolComboEditor::~KPropertySymbolComboEditor()
62 {
63  delete d;
64 }
65 
67 KPropertySymbolComboEditor::value() const
68 {
69  if (!(d->edit->text().isNull()))
70  return d->edit->text().at(0).unicode();
71  else
72  return 0;
73 }
74 
75 void
76 KPropertySymbolComboEditor::setValue(const QVariant &value, bool emitChange)
77 {
78  if (!(value.isNull()))
79  {
80  d->edit->blockSignals(true);
81  d->edit->setText(QChar(value.toInt()));
82  d->edit->blockSignals(false);
83  if (emitChange)
84  emit valueChanged(this);
85  }
86 }
87 
88 void
89 KPropertySymbolComboEditor::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
90 {
91  Widget::drawViewer(p, cg, r, QString(QChar(value.toInt())));
92 }
93 
94 void
95 KPropertySymbolComboEditor::selectChar()
96 {
97  QDialog dialog(this->topLevelWidget());
98  dialog.setWindowTitle(tr("Select Character", "Window title"));
99  dialog.setObjectName("charselect_dialog");
100  dialog.setButtons(QDialog::Ok | QDialog::Cancel);
101  dialog.setDefaultButton(QDialog::Ok);
102  dialog.setModal(false);
103 
104  KCharSelect *select = new KCharSelect(&dialog);
105  dialog.setObjectName("select_char");
106 //PORTING: Verify that widget was added to mainLayout: dialog.setMainWidget(select);
107 // Add mainLayout->addWidget(select); if necessary
108 
109  if (!(d->edit->text().isNull()))
110  select->setCurrentChar(d->edit->text().at(0));
111 
112  if (dialog.exec() == QDialog::Accepted)
113  d->edit->setText(select->currentChar());
114 }
115 
116 void
117 KPropertySymbolComboEditor::slotValueChanged(const QString&)
118 {
119  emit valueChanged(this);
120 }
121 
122 void
123 KPropertySymbolComboEditor::setReadOnlyInternal(bool readOnly)
124 {
125  d->select->setEnabled(!readOnly);
126 }
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QChar currentChar() const
int toInt(bool *ok) const const
bool isNull() const const
void setCurrentChar(const QChar &c)
The base class representing a single property.
Definition: KProperty.h:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:10:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.