Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating PluginManager widget

  • Loading branch information...
commit 97f452fb0261e74278bec24c9368fdaeaa0de1aa 1 parent bed91fc
@Ignotus authored
View
2  CMakeLists.txt
@@ -56,6 +56,7 @@ IF (UNIX)
ENDIF (UNIX)
SET (SRCS
+ pluginwidgetdelegate.cpp
brushcombo.cpp
graph.cpp
dottable.cpp
@@ -74,6 +75,7 @@ SET (SRCS
)
SET (HEADERS
+ pluginwidgetdelegate.hpp
brushcombo.hpp
graphpoint.hpp
graph.hpp
View
1  brushcombo.hpp
@@ -32,7 +32,6 @@ namespace KDots
{
class KDOTS_EXPORT BrushCombo : public KComboBox
{
- Q_OBJECT
public:
BrushCombo (QWidget* parent = 0);
void paintEvent (QPaintEvent *e);
View
1  brushcombodelegate.hpp
@@ -32,7 +32,6 @@ namespace KDots
{
class BrushComboDelegate : public QStyledItemDelegate
{
- Q_OBJECT
public:
static const QVector<Qt::BrushStyle>& brushes ();
static Qt::BrushStyle getBrushStyle (int index);
View
6 interface/iplugin.hpp
@@ -26,7 +26,7 @@
#ifndef KDOTS_IPLUGIN_HPP
#define KDOTS_IPLUGIN_HPP
#include <QString>
-#include <QIcon>
+#include <KIcon>
#include <QtPlugin>
namespace KDots
@@ -54,9 +54,9 @@ namespace KDots
/** @brief Returns a plugin icon.
*/
- virtual QIcon icon () const
+ virtual KIcon icon () const
{
- return QIcon ();
+ return KIcon ();
}
};
View
1  newgamewidget.hpp
@@ -38,7 +38,6 @@ namespace KDots
{
class NewGameWidget : public QWidget
{
- Q_OBJECT
public:
NewGameWidget (QWidget *parent = 0);
View
32 pluginmanagerwidget.cpp
@@ -24,9 +24,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "pluginmanagerwidget.hpp"
+#include <QStandardItemModel>
#include <interface/iplugin.hpp>
#include "kdots.h"
#include "plugincontainer.hpp"
+#include "pluginwidgetdelegate.hpp"
#include "ui_pluginmanagerwidget.h"
namespace KDots
@@ -37,29 +39,37 @@ namespace KDots
{
m_ui->setupUi (this);
+ QStandardItemModel *model = new QStandardItemModel (this);
for (IPlugin *plugin : PluginContainer::instance ().plugins ().values ())
- m_ui->PluginComboBox->addItem (plugin->icon (), plugin->name ());
+ model->appendRow (new QStandardItem (plugin->icon (), plugin->name ()));
- m_ui->PluginComboBox->setCurrentIndex (Settings::lastPlugin ());
- onIndexChanged (Settings::lastPlugin ());
-
- connect (m_ui->PluginComboBox,
- SIGNAL (currentIndexChanged (int)),
+ m_ui->PluginList->setModel (model);
+ m_ui->PluginList->setItemDelegate (new PluginWidgetDelegate (m_ui->PluginList));
+ m_ui->PluginList->setSelectionMode (QAbstractItemView::SingleSelection);
+ m_ui->PluginList->setEditTriggers (QAbstractItemView::NoEditTriggers);
+ connect (m_ui->PluginList,
+ SIGNAL (clicked (const QModelIndex&)),
this,
- SLOT (onIndexChanged (int)));
+ SLOT (onIndexChanged (const QModelIndex&)));
+
+ const QModelIndex& index =model->index (Settings::lastPlugin (), 0);
+ m_ui->PluginList->selectionModel ()->select (index, QItemSelectionModel::Select);
+ onIndexChanged (index);
}
- void PluginManagerWidget::onIndexChanged (int current)
+ void PluginManagerWidget::onIndexChanged (const QModelIndex& current)
{
- IPlugin *first = PluginContainer::instance ().plugin (m_ui->PluginComboBox->itemText (current));
+ const QString& pluginName = current.data ().toString ();
+ IPlugin *first = PluginContainer::instance ().plugin (pluginName);
m_ui->Description->setText (first->description ());
- Settings::setLastPlugin (current);
+ Settings::setLastPlugin (current.row ());
}
QString PluginManagerWidget::pluginName () const
{
- return m_ui->PluginComboBox->currentText ();
+ return m_ui->PluginList->selectionModel ()->selectedRows ()
+ .at (0).data ().toString ();
}
}
View
3  pluginmanagerwidget.hpp
@@ -28,6 +28,7 @@
#include <QWidget>
class QComboBox;
+class QModelIndex;
namespace Ui
{
@@ -46,7 +47,7 @@ namespace KDots
QString pluginName () const;
private slots:
- void onIndexChanged (int current);
+ void onIndexChanged (const QModelIndex& current);
};
}
View
60 plugins/ipconnect/configurationwidget.ui
@@ -20,7 +20,7 @@
<string>Game configuration</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="1" column="0">
+ <item row="0" column="0">
<widget class="KTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
@@ -30,6 +30,16 @@
<string>Create Game</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>You are:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
<item row="0" column="1">
<widget class="QSpinBox" name="listenPort">
<property name="maximum">
@@ -40,6 +50,16 @@
</property>
</widget>
</item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Connecting port:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
<item row="1" column="1">
<widget class="KComboBox" name="user">
<item>
@@ -54,33 +74,23 @@
</item>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Connecting port:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabWidgetPage2">
+ <attribute name="title">
+ <string>Join Game</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="label_4">
<property name="text">
- <string>You are:</string>
+ <string>Port:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- </layout>
- </widget>
- <widget class="QWidget" name="tabWidgetPage2">
- <attribute name="title">
- <string>Join Game</string>
- </attribute>
- <layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="1">
<widget class="KLineEdit" name="host">
<property name="inputMask">
@@ -111,16 +121,6 @@
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Port:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
</layout>
</widget>
</widget>
View
5 plugins/ipconnect/plugin.hpp
@@ -56,6 +56,11 @@ namespace KDots
{
return "Playing by internet connection";
}
+
+ KIcon icon () const
+ {
+ return KIcon ("network-connect");
+ }
};
}
View
5 plugins/simpleai/plugin.hpp
@@ -56,6 +56,11 @@ namespace KDots
{
return "Playing with the simple AI";
}
+
+ KIcon icon () const
+ {
+ return KIcon ("games-config-board");
+ }
};
}
View
5 plugins/singlepc/plugin.hpp
@@ -96,6 +96,11 @@ namespace KDots
{
return "Playing in the single PC";
}
+
+ KIcon icon () const
+ {
+ return KIcon ();
+ }
};
}
View
80 pluginwidgetdelegate.cpp
@@ -0,0 +1,80 @@
+/*
+ * KDots
+ * Copyright (c) 2011-2012 Minh Ngo <nlminhtl@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "pluginwidgetdelegate.hpp"
+#include <QPainter>
+#include <KApplication>
+#include <KDebug>
+#include "plugincontainer.hpp"
+#include "interface/iplugin.hpp"
+
+namespace KDots
+{
+ PluginWidgetDelegate::PluginWidgetDelegate (QObject *parent)
+ : QItemDelegate (parent)
+ {
+
+ }
+
+ void PluginWidgetDelegate::updateEditorGeometry (QWidget *editor,
+ const QStyleOptionViewItem& option, const QModelIndex&) const
+ {
+ editor->setGeometry (option.rect);
+ }
+
+ void PluginWidgetDelegate::paint (QPainter *painter, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
+ {
+ QStyleOptionViewItemV4 myOption = option;
+ KApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
+ const QString& pluginName = index.data ().toString ();
+
+ const QRect textRect (option.rect.x (), option.rect.y () + 30,
+ option.rect.width (), option.rect.height () - 30);
+
+ painter->drawText (textRect, Qt::AlignCenter, pluginName);
+ IPlugin *plug = PluginContainer::instance ().plugin (pluginName);
+ if (plug)
+ {
+ const KIcon& plugIcon = plug->icon ();
+ if (plugIcon.isNull ())
+ {
+ const KIcon newIcon ("applications-boardgames");
+ drawIcon (painter, option, newIcon);
+ }
+ else
+ drawIcon (painter, option, plugIcon);
+ }
+ }
+
+ void PluginWidgetDelegate::drawIcon (QPainter *painter,
+ const QStyleOptionViewItem& option, const KIcon& icon) const
+ {
+ const int delta = (option.rect.width () - 32) / 2;
+ const QRect iconRect (option.rect.x () + delta, option.rect.y () + 2, 28, 28);
+ const QPixmap& pixMap = icon.pixmap (iconRect.size ());
+ painter->drawPixmap (iconRect, pixMap, pixMap.rect ());
+ }
+}
View
55 pluginwidgetdelegate.hpp
@@ -0,0 +1,55 @@
+/*
+ * KDots
+ * Copyright (c) 2011-2012 Minh Ngo <nlminhtl@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef KDOTS_PLUGINWIDGETDELEGATE_HPP
+#define KDOTS_PLUGINWIDGETDELEGATE_HPP
+#include <QItemDelegate>
+
+class KIcon;
+
+namespace KDots
+{
+ class PluginWidgetDelegate : public QItemDelegate
+ {
+ public:
+ PluginWidgetDelegate (QObject *parent = 0);
+
+ QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
+ {
+ Q_UNUSED (index);
+ return QSize (option.rect.width (), 50);
+ }
+
+ void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const;
+
+ void paint (QPainter *painter, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const;
+ private:
+ void drawIcon (QPainter *painter, const QStyleOptionViewItem& option, const KIcon& icon) const;
+ };
+}
+
+#endif
View
13 ui/boardconfigwidget.ui
@@ -93,6 +93,19 @@
<item row="3" column="1">
<widget class="KDots::BrushCombo" name="kcfg_secondFillStyle"/>
</item>
+ <item row="4" column="1">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</widget>
</item>
View
4 ui/newgamedialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>483</width>
+ <height>333</height>
</rect>
</property>
<property name="windowTitle">
View
36 ui/pluginmanagerwidget.ui
@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>411</width>
+ <height>224</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="1" column="0">
+ <item row="1" column="1">
<widget class="KTextEdit" name="Description">
<property name="enabled">
<bool>true</bool>
@@ -24,40 +24,20 @@
</property>
</widget>
</item>
- <item row="0" column="0">
- <widget class="KComboBox" name="PluginComboBox">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>36</height>
- </size>
- </property>
- <property name="currentIndex">
- <number>-1</number>
- </property>
- <property name="iconSize">
+ <item row="1" column="0">
+ <widget class="QListView" name="PluginList">
+ <property name="maximumSize">
<size>
- <width>36</width>
- <height>36</height>
+ <width>150</width>
+ <height>16777215</height>
</size>
</property>
- <property name="duplicatesEnabled">
- <bool>false</bool>
- </property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
- <class>KComboBox</class>
- <extends>QComboBox</extends>
- <header>kcombobox.h</header>
- </customwidget>
- <customwidget>
<class>KTextEdit</class>
<extends>QTextEdit</extends>
<header>ktextedit.h</header>
Please sign in to comment.
Something went wrong with that request. Please try again.