Pimcommon

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

KDE's Doxygen guidelines are available online.