File indexing completed on 2024-05-12 16:39:56

0001 /* This file is part of the KDE project
0002    Copyright (C) 2011 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KexiTitleLabel.h"
0021 #include "utils.h"
0022 
0023 #include <QDebug>
0024 #include <QApplication>
0025 #include <QDesktopWidget>
0026 
0027 class Q_DECL_HIDDEN KexiTitleLabel::Private {
0028 public:
0029     Private() : updateFontEnabled(true) {}
0030     bool updateFontEnabled;
0031 };
0032 
0033 // ----
0034 
0035 KexiTitleLabel::KexiTitleLabel(QWidget * parent, Qt::WindowFlags f)
0036  : QLabel(parent, f)
0037  , d(new Private)
0038 {
0039     init();
0040 }
0041 
0042 KexiTitleLabel::KexiTitleLabel(const QString & text, QWidget * parent, Qt::WindowFlags f)
0043  : QLabel(text, parent, f)
0044  , d(new Private)
0045 {
0046     init();
0047 }
0048 
0049 void KexiTitleLabel::init()
0050 {
0051     setWordWrap(true);
0052     updateFont();
0053 }
0054 
0055 KexiTitleLabel::~KexiTitleLabel()
0056 {
0057     delete d;
0058 }
0059 
0060 void KexiTitleLabel::updateFont()
0061 {
0062     if (!d->updateFontEnabled)
0063         return;
0064     KexiUtils::BoolBlocker guard(&d->updateFontEnabled, false);
0065 
0066     qreal factor;
0067     QRect geo = QApplication::desktop()->availableGeometry(this);
0068     QFont f = font();
0069     if (geo.width() > 600 && geo.height() > 600) {
0070         factor = 2.0;
0071     }
0072     else {
0073         factor = 1.2;
0074         f.setBold(true);
0075     }
0076     //qDebug() << f.pointSize() << f.pixelSize();
0077     if (f.pointSize() == -1) {
0078         f.setPixelSize(qreal(f.pixelSize()) * factor);
0079     }
0080     else {
0081         f.setPointSize(f.pointSizeF() * factor);
0082     }
0083     setFont(f);
0084 }
0085 
0086 void KexiTitleLabel::changeEvent(QEvent* event)
0087 {
0088     QLabel::changeEvent(event);
0089     if (event->type() == QEvent::FontChange) {
0090         updateFont();
0091     }
0092 }
0093