--- a/src/qtgui/confgui/confgui.cpp
+++ b/src/qtgui/confgui/confgui.cpp
@@ -6,37 +6,11 @@
#include <stdlib.h>
#include <qglobal.h>
-#if QT_VERSION < 0x040000
-#define QFRAME_INCLUDE <qframe.h>
-#define QFILEDIALOG_INCLUDE <qfiledialog.h>
-#define QLISTBOX_INCLUDE <qlistbox.h>
-#define QFILEDIALOG QFileDialog
-#define QFRAME QFrame
-#define QHBOXLAYOUT QHBoxLayout
-#define QLISTBOX QListBox
-#define QLISTBOXITEM QListBoxItem
-#define QLBEXACTMATCH Qt::ExactMatch
-#define QVBOXLAYOUT QVBoxLayout
-#else
-#include <Q3HBoxLayout>
-#include <Q3VBoxLayout>
-
+#include <QHBoxLayout>
+#include <QVBoxLayout>
#include <QFrame>
-#define QFRAME_INCLUDE <q3frame.h>
-
#include <QFileDialog>
-#define QFILEDIALOG_INCLUDE <q3filedialog.h>
-
-#define QLISTBOX_INCLUDE <q3listbox.h>
-
-#define QFILEDIALOG Q3FileDialog
-#define QFRAME Q3Frame
-#define QHBOXLAYOUT Q3HBoxLayout
-#define QLISTBOX Q3ListBox
-#define QLISTBOXITEM Q3ListBoxItem
-#define QLBEXACTMATCH Q3ListBox::ExactMatch
-#define QVBOXLAYOUT Q3VBoxLayout
-#endif
+#include <QListWidget>
#include <qobject.h>
#include <qlayout.h>
@@ -47,13 +21,10 @@
#include <qtooltip.h>
#include <qlineedit.h>
#include <qcheckbox.h>
-#include QFILEDIALOG_INCLUDE
#include <qinputdialog.h>
#include <qpushbutton.h>
#include <qstringlist.h>
-#include QLISTBOX_INCLUDE
#include <qcombobox.h>
-#include QFRAME_INCLUDE
#include "confgui.h"
#include "smallut.h"
@@ -65,15 +36,15 @@
namespace confgui {
-const static int spacing = 4;
-const static int margin = 6;
+const static int spacing = 2;
+const static int margin = 2;
void ConfParamW::setValue(const QString& value)
{
if (m_fsencoding)
- m_cflink->set(string((const char *)value.local8Bit()));
+ m_cflink->set(string((const char *)value.toLocal8Bit()));
else
- m_cflink->set(string((const char *)value.utf8()));
+ m_cflink->set(string((const char *)value.toUtf8()));
}
void ConfParamW::setValue(int value)
@@ -89,19 +60,26 @@
m_cflink->set(string(buf));
}
+void setSzPol(QWidget *w, QSizePolicy::Policy hpol,
+ QSizePolicy::Policy vpol,
+ int hstretch, int vstretch)
+{
+ QSizePolicy policy(hpol, vpol);
+ policy.setHorizontalStretch(hstretch);
+ policy.setVerticalStretch(vstretch);
+ policy.setHeightForWidth(w->sizePolicy().hasHeightForWidth());
+ w->setSizePolicy(policy);
+}
+
bool ConfParamW::createCommon(const QString& lbltxt, const QString& tltptxt)
{
- m_hl = new QHBOXLAYOUT(this);
+ m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing);
QLabel *tl = new QLabel(this);
- tl->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- tl->sizePolicy().hasHeightForWidth() ) );
+ setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0);
tl->setText(lbltxt);
- QToolTip::add(tl, tltptxt);
+ tl->setToolTip(tltptxt);
m_hl->addWidget(tl);
@@ -120,21 +98,13 @@
return;
m_sb = new QSpinBox(this);
- m_sb->setMinValue(minvalue);
- m_sb->setMaxValue(maxvalue);
- m_sb->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- m_sb->sizePolicy().hasHeightForWidth()));
+ m_sb->setMinimum(minvalue);
+ m_sb->setMaximum(maxvalue);
+ setSzPol(m_sb, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0);
m_hl->addWidget(m_sb);
- QFRAME *fr = new QFRAME(this);
- fr->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 1, // Horizontal stretch
- 0, // Vertical stretch
- fr->sizePolicy().hasHeightForWidth() ) );
+ QFrame *fr = new QFrame(this);
+ setSzPol(fr, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0);
m_hl->addWidget(fr);
loadValue();
@@ -158,12 +128,10 @@
{
if (!createCommon(lbltxt, tltptxt))
return;
+
m_le = new QLineEdit(this);
- m_le->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 1, // Horizontal stretch
- 0, // Vertical stretch
- m_le->sizePolicy().hasHeightForWidth()));
+ setSzPol(m_le, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0);
+
m_hl->addWidget(m_le);
loadValue();
@@ -190,14 +158,12 @@
{
if (!createCommon(lbltxt, tltptxt))
return;
- m_cmb = new QComboBox(false, this);
- m_cmb->insertStringList(sl);
- // m_cmb->setEditable(false);
- m_cmb->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 1, // Horizontal stretch
- 0, // Vertical stretch
- m_cmb->sizePolicy().hasHeightForWidth()));
+ m_cmb = new QComboBox(this);
+ m_cmb->setEditable(FALSE);
+ m_cmb->insertItems(0, sl);
+
+ setSzPol(m_cmb, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0);
+
m_hl->addWidget(m_cmb);
loadValue();
@@ -216,8 +182,8 @@
cs = QString::fromUtf8(s.c_str());
for (int i = 0; i < m_cmb->count(); i++) {
- if (!cs.compare(m_cmb->text(i))) {
- m_cmb->setCurrentItem(i);
+ if (!cs.compare(m_cmb->itemText(i))) {
+ m_cmb->setCurrentIndex(i);
break;
}
}
@@ -229,29 +195,20 @@
: ConfParamW(parent, cflink)
{
// No createCommon because the checkbox has a label
- m_hl = new QHBOXLAYOUT(this);
+ m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing);
m_cb = new QCheckBox(lbltxt, this);
- m_cb->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- m_cb->sizePolicy().hasHeightForWidth()));
- QToolTip::add(m_cb, tltptxt);
+ setSzPol(m_cb, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0);
+ m_cb->setToolTip(tltptxt);
m_hl->addWidget(m_cb);
- QFRAME *fr = new QFRAME(this);
- fr->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 1, // Horizontal stretch
- 0, // Vertical stretch
- fr->sizePolicy().hasHeightForWidth()));
+ QFrame *fr = new QFrame(this);
+ setSzPol(fr, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0);
m_hl->addWidget(fr);
loadValue();
- QObject::connect(m_cb, SIGNAL(toggled(bool)),
- this, SLOT(setValue(bool)));
+ QObject::connect(m_cb, SIGNAL(toggled(bool)), this, SLOT(setValue(bool)));
}
void ConfParamBoolW::loadValue()
@@ -272,22 +229,14 @@
return;
m_fsencoding = true;
+
m_le = new QLineEdit(this);
m_le->setMinimumSize(QSize(150, 0 ));
- m_le->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 1, // Horizontal stretch
- 0, // Vertical stretch
- m_le->sizePolicy().hasHeightForWidth()));
+ setSzPol(m_le, QSizePolicy::Preferred, QSizePolicy::Fixed, 1, 0);
m_hl->addWidget(m_le);
m_pb = new QPushButton(this);
- m_pb->setText(tr("Browse"));
- m_pb->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- m_pb->sizePolicy().hasHeightForWidth()));
+ setSzPol(m_pb, QSizePolicy::Fixed, QSizePolicy::Fixed, 1, 0);
m_hl->addWidget(m_pb);
loadValue();
@@ -306,10 +255,18 @@
void ConfParamFNW::showBrowserDialog()
{
QString s = m_isdir ?
- QFILEDIALOG::getExistingDirectory() : QFILEDIALOG::getSaveFileName();
+ QFileDialog::getExistingDirectory() : QFileDialog::getSaveFileName();
if (!s.isEmpty())
m_le->setText(s);
}
+
+class SmallerListWidget: public QListWidget
+{
+public:
+ SmallerListWidget(QWidget *parent)
+ : QListWidget(parent) {}
+ virtual QSize sizeHint() {return QSize(150, 40);}
+};
ConfParamSLW::ConfParamSLW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
@@ -317,57 +274,37 @@
: ConfParamW(parent, cflink)
{
// Can't use createCommon here cause we want the buttons below the label
- m_hl = new QHBOXLAYOUT(this);
+ m_hl = new QHBoxLayout(this);
m_hl->setSpacing(spacing);
- QVBOXLAYOUT *vl1 = new QVBOXLAYOUT();
- QHBOXLAYOUT *hl1 = new QHBOXLAYOUT();
+ QVBoxLayout *vl1 = new QVBoxLayout();
+ QHBoxLayout *hl1 = new QHBoxLayout();
QLabel *tl = new QLabel(this);
- tl->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- tl->sizePolicy().hasHeightForWidth()));
+ setSzPol(tl, QSizePolicy::Preferred, QSizePolicy::Fixed, 0, 0);
tl->setText(lbltxt);
- QToolTip::add(tl, tltptxt);
+ tl->setToolTip(tltptxt);
vl1->addWidget(tl);
QPushButton *pbA = new QPushButton(this);
pbA->setText(tr("+"));
- pbA->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- pbA->sizePolicy().hasHeightForWidth()));
+ setSzPol(pbA, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0);
hl1->addWidget(pbA);
+
QPushButton *pbD = new QPushButton(this);
+ setSzPol(pbD, QSizePolicy::Fixed, QSizePolicy::Fixed, 0, 0);
pbD->setText(tr("-"));
- pbD->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
- QSizePolicy::Fixed,
- 0, // Horizontal stretch
- 0, // Vertical stretch
- pbD->sizePolicy().hasHeightForWidth()));
hl1->addWidget(pbD);
vl1->addLayout(hl1);
m_hl->addLayout(vl1);
- m_lb = new QLISTBOX(this);
- m_lb->setSelectionMode(QLISTBOX::Extended);
- m_lb->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Preferred,
- 1, // Horizontal stretch
- 1, // Vertical stretch
- m_lb->sizePolicy().hasHeightForWidth()));
+ m_lb = new SmallerListWidget(this);
+ m_lb->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ setSzPol(m_lb, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 1);
m_hl->addWidget(m_lb);
- this->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
- QSizePolicy::Preferred,
- 1, // Horizontal stretch
- 1, // Vertical stretch
- this->sizePolicy().hasHeightForWidth()));
-
+ setSzPol(this, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 1);
loadValue();
QObject::connect(pbA, SIGNAL(clicked()), this, SLOT(showInputDialog()));
QObject::connect(pbD, SIGNAL(clicked()), this, SLOT(deleteSelected()));
@@ -387,22 +324,25 @@
qls.push_back(QString::fromUtf8(it->c_str()));
}
m_lb->clear();
- m_lb->insertStringList(qls);
+ m_lb->insertItems(0, qls);
}
void ConfParamSLW::showInputDialog()
{
bool ok;
- QString s = QInputDialog::getText("", // Caption
- "", // Label
- QLineEdit::Normal, // Mode
- QString::null, // text
- &ok,
- this);
+ QString s = QInputDialog::getText (this,
+ "", // title
+ "", // label,
+ QLineEdit::Normal, // EchoMode mode
+ "", // const QString & text
+ &ok);
+
if (ok && !s.isEmpty()) {
- if (m_lb->findItem(s, QLBEXACTMATCH) == 0) {
- m_lb->insertItem(s);
- m_lb->sort();
+ QList<QListWidgetItem *>items =
+ m_lb->findItems(s, Qt::MatchFixedString|Qt::MatchCaseSensitive);
+ if (items.empty()) {
+ m_lb->insertItem(0, s);
+ m_lb->sortItems();
listToConf();
}
}
@@ -411,14 +351,15 @@
void ConfParamSLW::listToConf()
{
list<string> ls;
- for (unsigned int i = 0; i < m_lb->count(); i++) {
+ for (int i = 0; i < m_lb->count(); i++) {
// General parameters are encoded as utf-8. File names as
// local8bit There is no hope for 8bit file names anyway
// except for luck: the original encoding is unknown.
+ QString text = m_lb->item(i)->text();
if (m_fsencoding)
- ls.push_back((const char *)(m_lb->text(i).local8Bit()));
+ ls.push_back((const char *)(text.toLocal8Bit()));
else
- ls.push_back((const char *)(m_lb->text(i).utf8()));
+ ls.push_back((const char *)(text.toUtf8()));
}
string s;
stringsToString(ls, s);
@@ -430,10 +371,11 @@
bool didone;
do {
didone = false;
- for (unsigned int i = 0; i < m_lb->count(); i++) {
- if (m_lb->isSelected(i)) {
- emit entryDeleted(m_lb->text(i));
- m_lb->removeItem(i);
+ for (int i = 0; i < m_lb->count(); i++) {
+ if (m_lb->item(i)->isSelected()) {
+ emit entryDeleted(m_lb->item(i)->text());
+ QListWidgetItem *item = m_lb->takeItem(i);
+ delete item;
didone = true;
break;
}
@@ -445,14 +387,18 @@
// "Add entry" dialog for a file name list
void ConfParamDNLW::showInputDialog()
{
- QString s = QFILEDIALOG::getExistingDirectory();
+ QString s = QFileDialog::getExistingDirectory();
if (!s.isEmpty()) {
- if (m_lb->findItem(s, QLBEXACTMATCH) == 0) {
- m_lb->insertItem(s);
- m_lb->sort();
- QLISTBOXITEM *item = m_lb->findItem(s, QLBEXACTMATCH);
- if (m_lb->selectionMode() == QLISTBOX::Single && item)
- m_lb->setSelected(item, true);
+ QList<QListWidgetItem *>items =
+ m_lb->findItems(s, Qt::MatchFixedString|Qt::MatchCaseSensitive);
+ if (items.empty()) {
+ m_lb->insertItem(0, s);
+ m_lb->sortItems();
+ QList<QListWidgetItem *>items =
+ m_lb->findItems(s, Qt::MatchFixedString|Qt::MatchCaseSensitive);
+ if (m_lb->selectionMode() == QAbstractItemView::SingleSelection &&
+ !items.empty())
+ (*items.begin())->setSelected(TRUE);
listToConf();
}
}
@@ -462,16 +408,20 @@
void ConfParamCSLW::showInputDialog()
{
bool ok;
- QString s = QInputDialog::getItem("", // Caption
- "", // Label
- m_sl, // List
- 0, // current
- false, // editable,
- &ok);
+ QString s = QInputDialog::getItem (this, // parent
+ "", // title
+ "", // label,
+ m_sl, // items,
+ 0, // current = 0
+ FALSE, // editable = true,
+ &ok);
+
if (ok && !s.isEmpty()) {
- if (m_lb->findItem(s, QLBEXACTMATCH) == 0) {
- m_lb->insertItem(s);
- m_lb->sort();
+ QList<QListWidgetItem *>items =
+ m_lb->findItems(s, Qt::MatchFixedString|Qt::MatchCaseSensitive);
+ if (items.empty()) {
+ m_lb->insertItem(0, s);
+ m_lb->sortItems();
listToConf();
}
}