[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kstars/filtermanager] kstars/ekos/auxiliary: Add drawing delegates for filter manager
From: Jasem Mutlaq <null () kde ! org>
Date: 2017-09-30 19:55:50
Message-ID: E1dyNra-0002Vj-MD () code ! kde ! org
[Download RAW message or body]
Git commit c0b46682e6442c63c26e4815c1430e526e31eec9 by Jasem Mutlaq.
Committed on 30/09/2017 at 17:29.
Pushed by mutlaqja into branch 'filtermanager'.
Add drawing delegates for filter manager
A +186 -0 kstars/ekos/auxiliary/filterdelegate.cpp [License: GPL (v2+)]
A +100 -0 kstars/ekos/auxiliary/filterdelegate.h [License: GPL (v2+)]
https://commits.kde.org/kstars/c0b46682e6442c63c26e4815c1430e526e31eec9
diff --git a/kstars/ekos/auxiliary/filterdelegate.cpp \
b/kstars/ekos/auxiliary/filterdelegate.cpp new file mode 100644
index 000000000..979f4ce15
--- /dev/null
+++ b/kstars/ekos/auxiliary/filterdelegate.cpp
@@ -0,0 +1,186 @@
+/* Ekos Filter Delegates
+
+ Collection of delegates assigned to each individual column
+ in the table view.
+
+ Copyright (C) 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
+
+ This application 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.
+*/
+
+#include "filterdelegate.h"
+#include <QCheckBox>
+#include <QSpinBox>
+#include <QDoubleSpinBox>
+#include <QComboBox>
+#include <QApplication>
+
+QWidget * UseAutoFocusDelegate::createEditor(QWidget *parent, const \
QStyleOptionViewItem &, const QModelIndex &) const +{
+ cb = new QCheckBox(parent);
+ return cb;
+}
+
+
+void UseAutoFocusDelegate::setEditorData(QWidget *, const QModelIndex &index) const
+{
+ int value = index.model()->data(index, Qt::EditRole).toInt();
+ cb->setChecked(value == 1);
+}
+
+void UseAutoFocusDelegate::updateEditorGeometry(QWidget *editor, const \
QStyleOptionViewItem &option, const QModelIndex &) const +{
+ QStyleOptionButton checkboxstyle;
+ QRect checkbox_rect = \
QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkboxstyle); \
+ + //center
+ checkboxstyle.rect = option.rect;
+ checkboxstyle.rect.setLeft(option.rect.x() + option.rect.width()/2 - \
checkbox_rect.width()/2); +
+ editor->setGeometry(checkboxstyle.rect);
+}
+
+void UseAutoFocusDelegate::setModelData(QWidget *, QAbstractItemModel *model, const \
QModelIndex &index) const +{
+ int value = cb->isChecked() ? 1 : 0;
+ model->setData(index, value, Qt::EditRole);
+}
+
+void UseAutoFocusDelegate::paint(QPainter *painter, const QStyleOptionViewItem \
&option, const QModelIndex &index) const +{
+ //retrieve data
+ bool data = index.model()->data(index, Qt::DisplayRole).toBool();
+
+ //create CheckBox style
+ QStyleOptionButton checkboxstyle;
+ QRect checkbox_rect = \
QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkboxstyle); \
+ + //center
+ checkboxstyle.rect = option.rect;
+ checkboxstyle.rect.setLeft(option.rect.x() +
+ option.rect.width()/2 - checkbox_rect.width()/2);
+ //checked or not checked
+ if(data)
+ checkboxstyle.state = QStyle::State_On|QStyle::State_Enabled;
+ else
+ checkboxstyle.state = QStyle::State_Off|QStyle::State_Enabled;
+
+ //done! we can draw!
+ QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxstyle, \
painter); +}
+
+bool UseAutoFocusDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, \
const QStyleOptionViewItem &, + const QModelIndex \
&index) +{
+ if (event->type() == QEvent::MouseButtonRelease)
+ {
+ bool checked = index.model()->data(index, Qt::DisplayRole).toBool();
+ // Toggle value
+ int value = checked ? 0 : 1;
+ return model->setData(index, value, Qt::EditRole);
+ }
+
+ return false;
+}
+
+/////////////////////////////////////////////////////////
+// Exposure Delegate
+/////////////////////////////////////////////////////////
+
+QWidget * ExposureDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem \
&, const QModelIndex &) const +{
+ spinbox = new QDoubleSpinBox(parent);
+ spinbox->setFrame(false);
+ spinbox->setDecimals(3);
+ spinbox->setMinimum(0.001);
+ spinbox->setMaximum(120);
+ spinbox->setSingleStep(1);
+ return spinbox;
+}
+
+
+void ExposureDelegate::setEditorData(QWidget *, const QModelIndex &index) const
+{
+ double value = index.model()->data(index, Qt::EditRole).toDouble();
+ spinbox->setValue(value);
+}
+
+void ExposureDelegate::setModelData(QWidget *, QAbstractItemModel *model, const \
QModelIndex &index) const +{
+ double value = spinbox->value();
+ model->setData(index, value, Qt::EditRole);
+}
+
+void ExposureDelegate::updateEditorGeometry(QWidget *editor, const \
QStyleOptionViewItem &option, const QModelIndex &) const +{
+ editor->setGeometry(option.rect);
+}
+
+/////////////////////////////////////////////////////////
+// Offset Delegate
+/////////////////////////////////////////////////////////
+
+QWidget * OffsetDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem \
&, const QModelIndex &) const +{
+ spinbox = new QSpinBox(parent);
+ spinbox->setFrame(false);
+ spinbox->setMinimum(-10000);
+ spinbox->setMaximum(10000);
+ return spinbox;
+}
+
+
+void OffsetDelegate::setEditorData(QWidget *, const QModelIndex &index) const
+{
+ int value = index.model()->data(index, Qt::EditRole).toInt();
+ spinbox->setValue(value);
+}
+
+void OffsetDelegate::setModelData(QWidget *, QAbstractItemModel *model, const \
QModelIndex &index) const +{
+ int value = spinbox->value();
+ model->setData(index, value, Qt::EditRole);
+}
+
+void OffsetDelegate::updateEditorGeometry(QWidget *editor, const \
QStyleOptionViewItem &option, const QModelIndex &) const +{
+ editor->setGeometry(option.rect);
+}
+
+/////////////////////////////////////////////////////////
+// Lock Delegate
+/////////////////////////////////////////////////////////
+
+LockDelegate::LockDelegate(QStringList filterList, QObject *parent) : \
QStyledItemDelegate(parent) +{
+ m_FilterList = filterList;
+ m_FilterList.insert(0, "--");
+}
+
+QWidget * LockDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, \
const QModelIndex &) const +{
+ lockbox = new QComboBox(parent);
+ lockbox->addItems(m_FilterList);
+ return lockbox;
+}
+
+
+void LockDelegate::setEditorData(QWidget *, const QModelIndex &index) const
+{
+ QString currentLockFilter = index.model()->data(index, Qt::EditRole).toString();
+ lockbox->setCurrentText(currentLockFilter);
+}
+
+void LockDelegate::setModelData(QWidget *, QAbstractItemModel *model, const \
QModelIndex &index) const +{
+ QString value = lockbox->currentText();
+ model->setData(index, value, Qt::EditRole);
+}
+
+void LockDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem \
&option, const QModelIndex &) const +{
+ editor->setGeometry(option.rect);
+}
diff --git a/kstars/ekos/auxiliary/filterdelegate.h \
b/kstars/ekos/auxiliary/filterdelegate.h new file mode 100644
index 000000000..3a0035967
--- /dev/null
+++ b/kstars/ekos/auxiliary/filterdelegate.h
@@ -0,0 +1,100 @@
+/* Ekos Filter Delegates
+
+ Collection of delegates assigned to each individual column
+ in the table view.
+
+ Copyright (C) 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
+
+ This application 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.
+*/
+
+#pragma once
+
+#include <QStyledItemDelegate>
+
+class QCheckBox;
+class QSpinBox;
+class QDoubleSpinBox;
+class QComboBox;
+
+class NotEditableDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit NotEditableDelegate(QObject *parent = nullptr)
+ : QStyledItemDelegate(parent)
+ {}
+
+protected:
+ bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, \
const QModelIndex &) + { return false; }
+ QWidget* createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex \
&) const + { return nullptr; }
+};
+
+class UseAutoFocusDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit UseAutoFocusDelegate(QObject *parent = nullptr) : \
QStyledItemDelegate(parent) {} +
+ QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, \
const QModelIndex &index) const; + void setEditorData(QWidget *, const QModelIndex \
&index) const; + void updateEditorGeometry(QWidget *editor, const \
QStyleOptionViewItem &option, const QModelIndex &index) const; + void \
setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) \
const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const \
QModelIndex &index) const; + bool editorEvent(QEvent *event, QAbstractItemModel \
*model, const QStyleOptionViewItem &, const QModelIndex &index); +
+private:
+ mutable QCheckBox *cb = { nullptr };
+};
+
+class ExposureDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit ExposureDelegate(QObject *parent = nullptr) : \
QStyledItemDelegate(parent) {} +
+ QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, \
const QModelIndex &index) const; + void setEditorData(QWidget *, const QModelIndex \
&index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, \
const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, \
const QStyleOptionViewItem &option, const QModelIndex &index) const; +
+private:
+ mutable QDoubleSpinBox *spinbox = { nullptr };
+};
+
+class OffsetDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit OffsetDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) \
{} +
+ QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, \
const QModelIndex &index) const; + void setEditorData(QWidget *, const QModelIndex \
&index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, \
const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, \
const QStyleOptionViewItem &option, const QModelIndex &index) const; +
+private:
+ mutable QSpinBox *spinbox = { nullptr };
+};
+
+class LockDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit LockDelegate(QStringList filterList, QObject *parent = nullptr);
+
+ QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, \
const QModelIndex &index) const; + void setEditorData(QWidget *, const QModelIndex \
&index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, \
const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, \
const QStyleOptionViewItem &option, const QModelIndex &index) const; +
+private:
+ mutable QComboBox *lockbox = { nullptr };
+ QStringList m_FilterList;
+};
+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic