[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/kmldonkey
From:       Aleksey Markelov <markelovai () gmail ! com>
Date:       2009-07-01 14:49:04
Message-ID: 1246459744.926206.20615.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 990054 by amarkelov:

Ported MLDonkey configuration dialog option editor widget to Qt4.


 M  +50 -49    kmldonkey/optioneditor.cpp  
 M  +6 -7      kmldonkey/optioneditor.h  
 M  +20 -3     libkmldonkey/options.cpp  
 M  +16 -17    libkmldonkey/options.h  


--- trunk/extragear/network/kmldonkey/kmldonkey/optioneditor.cpp #990053:990054
@@ -21,6 +21,8 @@
  *
  */
 
+#include <QHeaderView>
+
 #include <kdebug.h>
 #include <klocale.h>
 
@@ -80,75 +82,74 @@
 
 
 
-OptionEditorWidget::OptionEditorWidget(QWidget* parent, const char* name)
-    : Q3Table(0, 2, parent, name)
-    //, QToolTip( viewport() )
+OptionEditorWidget::OptionEditorWidget(QWidget* parent)
+    : QTableWidget(0, 2, parent)
 {
     setSelectionMode(NoSelection);
-    setColumnReadOnly(0, true);
-    setColumnStretchable(1, true);
     verticalHeader()->hide();
-    setLeftMargin(0);
-    horizontalHeader()->setLabel(0, i18n("Option"));
-    horizontalHeader()->setLabel(1, i18n("Value"));
-    connect(this, SIGNAL(valueChanged(int, int)), SLOT(optionChanged(int, int)));
+    horizontalHeader()->setStretchLastSection(true);
+    setHorizontalHeaderLabels( QStringList() << i18n("Option") << i18n("Value") );
+    setEditTriggers(QAbstractItemView::AllEditTriggers);
+    connect(this, SIGNAL(itemChanged(QTableWidgetItem*)), SLOT(optionChanged(QTableWidgetItem*)));
 }
 
-void OptionEditorWidget::maybeTip(const QPoint& vp)
-{
-#if 0 //sebsauer
-    QPoint p(viewportToContents(vp));
-    int row = rowAt(p.y()), col = columnAt(p.x());
-    if (col < 0 || row < 0)
-        return;
 
-    QString help = m_options[row].option().optionHelp();
-    if (help.isEmpty() && col)
-        help = m_options[row].option().optionLabel();
-    if (help.isEmpty())
-        return;
 
-    QRect r = cellGeometry(row, col);
-    r.moveTopLeft(contentsToViewport(r.topLeft()));
-    tip(r, help);
-#else
-    Q_UNUSED(vp);
-    #ifdef __GNUC__
-        #warning Port it!
-    #endif
-#endif
-}
-
 void OptionEditorWidget::addOption(const DonkeyOption& option)
 {
-    int row = numRows();
-    setNumRows(row + 1);
-    setText(row, 0, option.optionLabel());
+    int row = rowCount();
+    insertRow(row);
+
+    QTableWidgetItem *nameItem = new QTableWidgetItem(option.optionLabel());
+    nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
+    setItem(row, 0, nameItem);
+
     QString value = KMLDonkey::App->donkey->getOption(option.optionName());
-    if (option.optionType() == "Bool") {
-        QStringList list;
-        list << "true" << "false";
-        Q3ComboTableItem* item;
-        setItem(row, 1, item = new Q3ComboTableItem(this, list));
-        item->setCurrentItem(value);
+    QVariant variantValue = value;
+    QTableWidgetItem *valueItem = new QTableWidgetItem();
+    switch (option.type()) {
+    case DonkeyOption::Boolean:
+        variantValue.convert(QVariant::Bool);
+        break;
+    case DonkeyOption::Integer:
+        variantValue.convert(QVariant::Int);
+        break;
+    case DonkeyOption::Float:
+        variantValue.convert(QVariant::Double);
+        break;
+    //TODO: create delegate to set validator for Ip/IpList/Address/Md4/Sha1 types
+    default: break;
     }
-    else
-        setText(row, 1, value);
-    adjustColumn(0);
+    valueItem->setData(Qt::DisplayRole, variantValue);
+    setItem(row, 1, valueItem);
+
+    nameItem->setToolTip(option.optionHelp());
+    valueItem->setToolTip(option.optionHelp());
+
+    resizeColumnToContents(0);
+    resizeRowToContents(row);
+
     m_options.append(MyDonkeyOption(option, value));
 }
 
-void OptionEditorWidget::optionChanged(int row, int col)
+
+void OptionEditorWidget::optionChanged(QTableWidgetItem *item)
 {
-    m_options[row].setValue(text(row,col));
+    if (m_options.size() <= item->row()) {
+        return;//ignore signals emitted in addOption
+    }
+    m_options[item->row()].setValue(item->text());
     emit listIsDirty();
 }
 
 void OptionEditorWidget::applyChangedOptions(DonkeyProtocol* target)
 {
-    foreach(MyDonkeyOption option, m_options)
-        if (option.isDirty())
-            option.applyOption(target);
+    OptionList::iterator it = m_options.begin(), itend = m_options.end();
+    for (; it != itend; ++it) {
+        if (it->isDirty()) {
+            it->applyOption(target);
+        }
+    }
 }
 
 
--- trunk/extragear/network/kmldonkey/kmldonkey/optioneditor.h #990053:990054
@@ -24,9 +24,8 @@
 #ifndef __kmldonkey_optioneditor_h__
 #define __kmldonkey_optioneditor_h__
 
-#include <q3table.h>
-#include <QToolTip>
 #include <QList>
+#include <QTableWidget>
 
 #include <options.h>
 
@@ -49,21 +48,20 @@
     bool m_dirty;
 };
 
-class OptionEditorWidget : public Q3Table //, public QToolTip
+class OptionEditorWidget : public QTableWidget
 {
     Q_OBJECT
 
 public:
 
-    OptionEditorWidget(QWidget* parent = 0, const char* name = 0);
+    OptionEditorWidget(QWidget* parent = 0);
     
     void addOption(const DonkeyOption& option);
     void applyChangedOptions(DonkeyProtocol*);
-    void maybeTip(const QPoint& p);
 
 protected slots:
     
-    void optionChanged(int, int);
+    void optionChanged(QTableWidgetItem *item);
 
 signals:
 
@@ -71,7 +69,8 @@
 
 private:
 
-    QList<MyDonkeyOption> m_options;
+    typedef QList<MyDonkeyOption> OptionList;
+    OptionList m_options;
 
 };
 
--- trunk/extragear/network/kmldonkey/libkmldonkey/options.cpp #990053:990054
@@ -25,6 +25,23 @@
 
 #include <kdebug.h>
 
+inline DonkeyOption::OptionType typeFromName(const QString &typeName)
+{
+    static const char * const typeNames[] = { "String", "Integer", "Float",
+        "Bool", "Ip", "Ip List",
+        "Addr", "Md4", "Sha1" };
+
+    if (typeName == "Int") {
+        return DonkeyOption::Integer;
+    }
+    for (uint i = 0; i < sizeof(typeNames)/sizeof(typeNames[0]); ++i) {
+        if (typeName == typeNames[i]) {
+            return (DonkeyOption::OptionType)i;
+        }
+    }
+    return DonkeyOption::Unknown;
+}
+
 DonkeyOption::DonkeyOption(DonkeyMessage* msg, int /*proto*/)
 {
     bool ok = true;
@@ -32,7 +49,7 @@
     if (ok) {
         label = msg->readString();
         name = msg->readString();
-        type = msg->readString();
+        m_type = typeFromName( msg->readString() );
         help = msg->readString();
         value = msg->readString();
         defaultValue = msg->readString();
@@ -49,7 +66,7 @@
     section = o.optionSection();
     label = o.optionLabel();
     name = o.optionName();
-    type = o.optionType();
+    m_type = o.type();
     help = o.optionHelp();
     value = o.optionValue();
     defaultValue = o.optionDefaultValue();
@@ -63,7 +80,7 @@
 const QString& DonkeyOption::optionSection() const { return section; }
 const QString& DonkeyOption::optionLabel() const { return label; }
 const QString& DonkeyOption::optionName() const { return name; }
-const QString& DonkeyOption::optionType() const { return type; }
+DonkeyOption::OptionType DonkeyOption::type() const { return m_type; }
 const QString& DonkeyOption::optionHelp() const { return help; }
 const QString& DonkeyOption::optionValue() const { return value; }
 const QString& DonkeyOption::optionDefaultValue() const { return defaultValue; }
--- trunk/extragear/network/kmldonkey/libkmldonkey/options.h #990053:990054
@@ -35,7 +35,19 @@
 {
 
 public:
-
+    /// Possible type values:
+    enum OptionType {
+        String = 0, ///< a text string
+        Integer, ///< an integer value ("Integer" or "Int" type tag)
+        Float, ///< a floating point value
+        Boolean, ///< a boolean value, either \c "true" or \c "false"
+        Ip, ///< an IP address
+        IpList, ///< a list of IP addresses separated by spaces ("Ip List" type tag)
+        Address, ///< an IP address and port number, separated by a color ("Addr" type tag)
+        Md4, ///< an MD4 hash in hexadecimal form
+        Sha1, ///< an SHA1 hash in hexadecimal form
+        Unknown ///< value reserved for non-described types, should be treated as string?
+    };
     DonkeyOption(DonkeyMessage* msg, int proto);
     DonkeyOption(const DonkeyOption&);
     DonkeyOption() { advanced = false; }
@@ -48,21 +60,7 @@
     //! The option name.
     const QString& optionName() const;
     //! The option type.
-    /*!
-     * Possible type values:
-     *
-     * \li \c "String" a text string
-     * \li \c "Int" an integer value
-     * \li \c "Integer" alternative form of \c "Int" that appears occasionally
-     * \li \c "Float" a floating point value
-     * \li \c "Bool" a boolean value, either \c "true" or \c "false"
-     * \li \c "Ip" an IP address
-     * \li \c "Ip List" a list of IP addresses separated by spaces
-     * \li \c "Addr" an IP address and port number, separated by a colon
-     * \li \c "Md4" an MD4 hash
-     * \li \c "Sha1" an SHA1 hash
-     */
-    const QString& optionType() const;
+    OptionType type() const;
     //! The option's help string.
     const QString& optionHelp() const;
     //! The option's current value.
@@ -74,7 +72,8 @@
 
 private:
 
-    QString section, label, name, type, help, value, defaultValue;
+    QString section, label, name, help, value, defaultValue;
+    OptionType m_type;
     bool advanced;
 
 };

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic