add more spacing
[personal-kdebase.git] / apps / konqueror / src / konqcloseditem.cpp
blobb4bd7207525fb36886c5c574404c86dc74a4e8cc
1 /* This file is part of the KDE project
2 Copyright 2007 David Faure <faure@kde.org>
3 Copyright 2007 Eduardo Robles Elvira <edulix@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "konqcloseditem.h"
22 #include "konqclosedwindowsmanager.h"
23 #include <QFile>
24 #include <QFont>
25 #include <QFontMetrics>
26 #include <QPainter>
27 #include <kconfig.h>
28 #include <kdebug.h>
29 #include <kglobal.h>
30 #include <kglobalsettings.h>
31 #include <kicon.h>
32 #include <kiconeffect.h>
33 #include <konqpixmapprovider.h>
34 #include <kcolorscheme.h>
35 #include <kstandarddirs.h>
36 #include <unistd.h>
38 class KonqIcon {
39 public:
40 KonqIcon()
41 : image(KIcon("konqueror").pixmap(16).toImage())
43 KIconEffect::deSaturate(image, 0.60f);
46 QImage image;
49 K_GLOBAL_STATIC(KonqIcon, s_lightIconImage)
51 KonqClosedItem::KonqClosedItem(const QString& title, const QString& group, quint64 serialNumber)
52 : m_title(title), m_configGroup(KonqClosedWindowsManager::self()->config(), group), m_serialNumber(serialNumber)
56 KonqClosedItem::~KonqClosedItem()
58 m_configGroup.deleteGroup();
59 kDebug(1202) << "deleted group" << m_configGroup.name();
62 KonqClosedTabItem::KonqClosedTabItem(const QString& url, const QString& title, int pos, quint64 serialNumber)
63 : KonqClosedItem(title, "Closed_Tab" + QString::number((qint64)this), serialNumber), m_url(url), m_pos(pos)
65 kDebug(1202) << m_configGroup.name();
68 KonqClosedTabItem::~KonqClosedTabItem()
70 m_configGroup.deleteGroup();
71 kDebug(1202) << "deleted group" << m_configGroup.name();
74 QPixmap KonqClosedTabItem::icon() const {
75 return KonqPixmapProvider::self()->pixmapFor(m_url);
78 KonqClosedWindowItem::KonqClosedWindowItem(const QString& title, quint64 serialNumber, int numTabs)
79 : KonqClosedItem(title, "Closed_Window" + QString::number((qint64)this), serialNumber), m_numTabs(numTabs)
81 kDebug(1202) << m_configGroup.name();
84 KonqClosedWindowItem::~KonqClosedWindowItem()
86 // Do this manually when needed:
87 // m_configGroup.deleteGroup();
90 QPixmap KonqClosedWindowItem::icon() const
92 QImage overlayImg = s_lightIconImage->image.copy();
93 int oldWidth = overlayImg.width();
94 QString countStr = QString::number( m_numTabs );
96 QFont f = KGlobalSettings::generalFont();
97 f.setBold(true);
99 float pointSize = f.pointSizeF();
100 QFontMetrics fm(f);
101 int w = fm.width(countStr);
102 if( w > (oldWidth) )
104 pointSize *= float(oldWidth) / float(w);
105 f.setPointSizeF(pointSize);
108 // overlay
109 QPainter p(&overlayImg);
110 p.setFont(f);
111 KColorScheme scheme(QPalette::Active, KColorScheme::Window);
112 p.setPen(scheme.foreground(KColorScheme::LinkText).color());
113 p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr);
115 return QPixmap::fromImage(overlayImg);
118 int KonqClosedWindowItem::numTabs() const
120 return m_numTabs;
123 KonqClosedRemoteWindowItem::KonqClosedRemoteWindowItem(const QString& title,
124 const QString& groupName, const QString& configFileName, quint64 serialNumber,
125 int numTabs, const QString& dbusService)
126 : KonqClosedWindowItem(title, serialNumber, numTabs),
127 m_remoteGroupName(groupName), m_remoteConfigFileName(configFileName),
128 m_dbusService(dbusService), m_remoteConfigGroup(0L), m_remoteConfig(0L)
130 kDebug();
133 KonqClosedRemoteWindowItem::~KonqClosedRemoteWindowItem()
135 delete m_remoteConfigGroup;
136 delete m_remoteConfig;
139 void KonqClosedRemoteWindowItem::readConfig() const
141 // only do this once
142 if(m_remoteConfig || m_remoteConfigGroup)
143 return;
145 m_remoteConfig = new KConfig(
146 KStandardDirs::locateLocal("appdata", m_remoteConfigFileName),
147 KConfig::SimpleConfig, "appdata");
148 m_remoteConfigGroup = new KConfigGroup(m_remoteConfig, m_remoteGroupName);
149 kDebug();
152 const KConfigGroup& KonqClosedRemoteWindowItem::configGroup() const
154 readConfig();
155 return *m_remoteConfigGroup;
158 KConfigGroup& KonqClosedRemoteWindowItem::configGroup()
160 readConfig();
161 return *m_remoteConfigGroup;
164 bool KonqClosedRemoteWindowItem::equalsTo(const QString& groupName,
165 const QString& configFileName) const
167 return (m_remoteGroupName == groupName &&
168 m_remoteConfigFileName == configFileName);