• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • configuredialog
  • configureagents
configureagentlistdelegate.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include "configureagentlistdelegate.h"
20 #include "configureagentlistmodel.h"
21 
22 #include <KIcon>
23 #include <QLabel>
24 #include <QPainter>
25 #include <QPushButton>
26 #include <QToolButton>
27 #include <qcheckbox.h>
28 
29 ConfigureAgentListDelegate::ConfigureAgentListDelegate(QAbstractItemView* itemView, QObject* parent)
30  : KWidgetItemDelegate(itemView, parent)
31 {
32 }
33 
34 ConfigureAgentListDelegate::~ConfigureAgentListDelegate()
35 {
36 }
37 
38 QSize ConfigureAgentListDelegate::sizeHint(const QStyleOptionViewItem &option,
39  const QModelIndex &index) const
40 {
41  Q_UNUSED(index);
42 
43  const QStyle *style = itemView()->style();
44  const int buttonHeight = style->pixelMetric(QStyle::PM_ButtonMargin) * 2 +
45  style->pixelMetric(QStyle::PM_ButtonIconSize);
46  const int fontHeight = option.fontMetrics.height();
47  return QSize(100, qMax(buttonHeight, fontHeight));
48 }
49 
50 void ConfigureAgentListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
51  const QModelIndex& index) const
52 {
53  Q_UNUSED(index);
54  painter->save();
55 
56  itemView()->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
57 
58  if (option.state & QStyle::State_Selected) {
59  painter->setPen(option.palette.highlightedText().color());
60  }
61 
62  painter->restore();
63 }
64 
65 QList<QWidget*> ConfigureAgentListDelegate::createItemWidgets() const
66 {
67  QCheckBox* checkBox = new QCheckBox();
68  QPalette palette = checkBox->palette();
69  palette.setColor(QPalette::WindowText, palette.color(QPalette::Text));
70  checkBox->setPalette(palette);
71  connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(slotCheckboxClicked(bool)));
72 
73  QPushButton* configureButton = new QPushButton();
74  connect(configureButton, SIGNAL(clicked()), this, SLOT(slotConfigure()));
75 
76  return QList<QWidget*>() << checkBox << configureButton;
77 }
78 
79 void ConfigureAgentListDelegate::updateItemWidgets(const QList<QWidget*> widgets,
80  const QStyleOptionViewItem& option,
81  const QPersistentModelIndex& index) const
82 {
83  QCheckBox* checkBox = static_cast<QCheckBox*>(widgets[0]);
84  QPushButton *configureButton = static_cast<QPushButton*>(widgets[1]);
85 
86  const int itemHeight = sizeHint(option, index).height();
87 
88  const QAbstractItemModel* model = index.model();
89  checkBox->setText(model->data(index).toString());
90  checkBox->setChecked(model->data(index, Qt::CheckStateRole).toBool());
91 
92  const QColor color = model->data(index, Qt::BackgroundColorRole).value<QColor>();
93  QPalette palette = checkBox->palette();
94  if (color.isValid()) {
95  palette.setColor(QPalette::WindowText, color);
96  checkBox->setPalette(palette);
97  } else {
98  palette.setColor(QPalette::WindowText, palette.color(QPalette::Text));
99  checkBox->setPalette(palette);
100  }
101 
102  int checkBoxWidth = option.rect.width();
103  checkBoxWidth -= configureButton->sizeHint().width();
104  checkBox->resize(checkBoxWidth, checkBox->sizeHint().height());
105  checkBox->move(0, (itemHeight - checkBox->height()) / 2);
106 
107  bool failed = model->data(index, ConfigureAgentListModel::FailedRole).toBool();
108  configureButton->setEnabled(!failed);
109  configureButton->setIcon(KIcon(QLatin1String("configure")));
110  configureButton->resize(configureButton->sizeHint());
111  configureButton->move(option.rect.right() - configureButton->width(),
112  (itemHeight - configureButton->height()) / 2);
113 }
114 
115 void ConfigureAgentListDelegate::slotCheckboxClicked(bool checked)
116 {
117  QAbstractItemModel* model = const_cast<QAbstractItemModel*>(focusedIndex().model());
118  model->setData(focusedIndex(), checked, Qt::CheckStateRole);
119 }
120 
121 void ConfigureAgentListDelegate::slotConfigure()
122 {
123  Q_EMIT requestConfiguration(focusedIndex());
124 }
QModelIndex
ConfigureAgentListDelegate::createItemWidgets
virtual QList< QWidget * > createItemWidgets() const
Definition: configureagentlistdelegate.cpp:65
QWidget::palette
palette
QSize::width
int width() const
QAbstractItemView
QPushButton::sizeHint
virtual QSize sizeHint() const
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
ConfigureAgentListDelegate::ConfigureAgentListDelegate
ConfigureAgentListDelegate(QAbstractItemView *itemView, QObject *parent=0)
Definition: configureagentlistdelegate.cpp:29
ConfigureAgentListDelegate::updateItemWidgets
virtual void updateItemWidgets(const QList< QWidget * > widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const
Definition: configureagentlistdelegate.cpp:79
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QCheckBox::sizeHint
virtual QSize sizeHint() const
QPainter::save
void save()
QVariant::value
T value() const
QPersistentModelIndex::model
const QAbstractItemModel * model() const
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
KWidgetItemDelegate
QWidget::width
width
QWidget::resize
void resize(int w, int h)
ConfigureAgentListDelegate::requestConfiguration
void requestConfiguration(const QModelIndex &index)
QWidget::setEnabled
void setEnabled(bool)
ConfigureAgentListDelegate::~ConfigureAgentListDelegate
virtual ~ConfigureAgentListDelegate()
Definition: configureagentlistdelegate.cpp:34
QStyleOptionViewItem
QObject
QStyle
QPainter::setPen
void setPen(const QColor &color)
QCheckBox
ConfigureAgentListModel::FailedRole
Definition: configureagentlistmodel.h:37
QPainter
QWidget::move
void move(int x, int y)
configureagentlistmodel.h
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QList
QColor
ConfigureAgentListDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: configureagentlistdelegate.cpp:38
QSize
configureagentlistdelegate.h
QPainter::restore
void restore()
QAbstractButton::setChecked
void setChecked(bool)
QPersistentModelIndex
QLatin1String
QSize::height
int height() const
QVariant::toBool
bool toBool() const
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAbstractButton::setText
void setText(const QString &text)
QPushButton
ConfigureAgentListDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: configureagentlistdelegate.cpp:50
QVariant::toString
QString toString() const
QPalette
QWidget::height
height
QColor::isValid
bool isValid() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal