Pimcommon

customtreeview.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2020 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "customtreeview.h"
8 
9 #include <QPainter>
10 #include <QFontDatabase>
11 #include <QEvent>
12 
13 using namespace PimCommon;
14 
15 CustomTreeView::CustomTreeView(QWidget *parent)
16  : QTreeWidget(parent)
17 {
18 }
19 
20 CustomTreeView::~CustomTreeView()
21 {
22 }
23 
24 void CustomTreeView::changeEvent(QEvent *event)
25 {
26  if (event->type() == QEvent::PaletteChange) {
27  generalPaletteChanged();
28  } else if (event->type() == QEvent::FontChange) {
29  generalFontChanged();
30  }
32 }
33 
34 void CustomTreeView::setShowDefaultText(bool b)
35 {
36  if (mShowDefaultText != b) {
37  mShowDefaultText = b;
38  update();
39  }
40 }
41 
42 bool CustomTreeView::showDefaultText() const
43 {
44  return mShowDefaultText;
45 }
46 
47 void CustomTreeView::setDefaultText(const QString &text)
48 {
49  if (mDefaultText != text) {
50  mDefaultText = text;
51  update();
52  }
53 }
54 
55 void CustomTreeView::generalPaletteChanged()
56 {
57  const QPalette palette = viewport()->palette();
58  QColor color = palette.text().color();
59  color.setAlpha(128);
60  mTextColor = color;
61 }
62 
63 void CustomTreeView::generalFontChanged()
64 {
66 }
67 
68 void CustomTreeView::paintEvent(QPaintEvent *event)
69 {
70  if (mShowDefaultText && !mDefaultText.isEmpty()) {
71  QPainter p(viewport());
72 
73  QFont font = p.font();
74  font.setItalic(true);
75  p.setFont(font);
76 
77  if (!mTextColor.isValid()) {
78  generalPaletteChanged();
79  }
80  p.setPen(mTextColor);
81 
82  p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter, mDefaultText);
83  } else {
85  }
86 }
QEvent::Type type() const const
const QPalette & palette() const const
virtual void paintEvent(QPaintEvent *event) override
const QBrush & text() const const
folderdialogacltab.h
void setAlpha(int alpha)
void update()
AlignCenter
int width() const const
const QColor & color() const const
virtual void changeEvent(QEvent *ev) override
void setFont(const QFont &)
void setItalic(bool enable)
QFont systemFont(QFontDatabase::SystemFont type)
virtual bool event(QEvent *event) override
int height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Sep 21 2020 23:17:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.