aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui/radioitemdelegate.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2012-08-29 20:39:30 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2012-08-29 20:39:30 +0000
commit471b1754f75e462cb6e5dc52d66bdec5745c92e0 (patch)
tree9dbc1541bb9221077cc953991e3b485def9717c6 /src/qmmpui/radioitemdelegate.cpp
parent1abba773217ac19dbcc7f413bfaf8376caf8ba42 (diff)
downloadqmmp-471b1754f75e462cb6e5dc52d66bdec5745c92e0.tar.gz
qmmp-471b1754f75e462cb6e5dc52d66bdec5745c92e0.tar.bz2
qmmp-471b1754f75e462cb6e5dc52d66bdec5745c92e0.zip
changed configuration dialog
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2908 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui/radioitemdelegate.cpp')
-rw-r--r--src/qmmpui/radioitemdelegate.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/qmmpui/radioitemdelegate.cpp b/src/qmmpui/radioitemdelegate.cpp
new file mode 100644
index 000000000..1c1af928b
--- /dev/null
+++ b/src/qmmpui/radioitemdelegate.cpp
@@ -0,0 +1,112 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <QApplication>
+#include <QMouseEvent>
+#include "radioitemdelegate_p.h"
+
+RadioItemDelegate::RadioItemDelegate(QObject *parent) : QStyledItemDelegate(parent)
+{
+}
+
+void RadioItemDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (hasRadioButton(index))
+ {
+ QStyleOptionViewItemV4 opt = option;
+
+ initStyleOption(&opt, index);
+
+ QStyleOptionButton buttonOption;
+ buttonOption.rect = option.rect;
+ buttonOption.text = index.data(Qt::DisplayRole).toString();
+ buttonOption.state |= QStyle::State_Enabled;
+
+ if (index.data(Qt::CheckStateRole) == Qt::Checked)
+ {
+ buttonOption.state |= QStyle::State_On;
+ buttonOption.state &=~ QStyle::State_Off;
+ }
+ else
+ {
+ buttonOption.state |= QStyle::State_Off;
+ buttonOption.state &=~ QStyle::State_On;
+ }
+
+ buttonOption.palette = opt.palette;
+
+ if(opt.state.testFlag(QStyle::State_Selected))
+ {
+ buttonOption.palette.setBrush(QPalette::ButtonText,
+ opt.palette.brush(QPalette::HighlightedText));
+ qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter);
+ }
+ qApp->style()->drawControl(QStyle::CE_RadioButton, &buttonOption, painter);
+ }
+ else
+ {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+}
+
+QSize RadioItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QSize size = QStyledItemDelegate::sizeHint(option, index);
+ if (hasRadioButton(index))
+ {
+ int buttonHeight = qApp->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight, &option);
+ size.setHeight(qMax(size.height(), buttonHeight));
+ }
+ return size;
+}
+
+bool RadioItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
+ const QStyleOptionViewItem &option, const QModelIndex &index)
+{
+ if (event->type() == QEvent::MouseButtonRelease)
+ {
+ if (hasRadioButton(index))
+ {
+ QRect checkRect = qApp->style()->subElementRect(QStyle::SE_RadioButtonIndicator, &option);
+
+ QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
+ if (checkRect.contains(mouseEvent->pos()) && !index.data(Qt::CheckStateRole).toBool())
+ {
+ model->setData(index, Qt::Checked, Qt::CheckStateRole);
+ QModelIndex parentItem = index.parent();
+ for (int i = 0; i < model->rowCount(parentItem); ++i)
+ {
+ QModelIndex childIndex = parentItem.child(i,0);
+ if (childIndex != index)
+ model->setData(childIndex, Qt::Unchecked, Qt::CheckStateRole);
+ }
+ return true;
+ }
+ }
+ }
+ return QStyledItemDelegate::editorEvent(event,model,option,index);
+}
+
+bool RadioItemDelegate::hasRadioButton(const QModelIndex &index) const
+{
+ return index.flags().testFlag(Qt::ItemIsUserCheckable) && index.data(RadioButtonRole).toBool();
+}