-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathbasketstatusbar.cpp
194 lines (165 loc) · 6.83 KB
/
basketstatusbar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/***************************************************************************
* Copyright (C) 2003 by Sébastien Laoût *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "basketstatusbar.h"
#include <KDE/KLocale>
#include <KDE/KStatusBar>
#include <KParts/StatusBarExtension>
#include <QtCore/QObject>
#include <QtGui/QLabel>
#include <QtGui/QPixmap>
#include <QtGui/QMouseEvent>
#include "global.h"
#include "bnpview.h"
#include "basketscene.h"
#include "tools.h"
BasketStatusBar::BasketStatusBar(KStatusBar *bar)
: m_bar(bar), m_extension(0), m_selectionStatus(0), m_lockStatus(0), m_basketStatus(0), m_savedStatus(0)
{
}
BasketStatusBar::BasketStatusBar(KParts::StatusBarExtension *extension)
: m_bar(0), m_extension(extension), m_selectionStatus(0), m_lockStatus(0), m_basketStatus(0), m_savedStatus(0)
{
}
BasketStatusBar::~BasketStatusBar()
{
//delete m_extension;
}
KStatusBar *BasketStatusBar::statusBar() const
{
if (m_extension)
return m_extension->statusBar();
else
return m_bar;
}
void BasketStatusBar::addWidget(QWidget * widget, int stretch, bool permanent)
{
if (m_extension)
m_extension->addStatusBarItem(widget, stretch, permanent);
else if (permanent)
m_bar->addPermanentWidget(widget, stretch);
else
m_bar->addWidget(widget, stretch);
}
void BasketStatusBar::setupStatusBar()
{
QWidget* parent = statusBar();
QObjectList lst = parent->findChildren<QObject*>("KRSqueezedTextLabel");
//Tools::printChildren(parent);
if (lst.count() == 0) {
m_basketStatus = new QLabel(parent);
QSizePolicy policy(QSizePolicy::Ignored, QSizePolicy::Ignored);
policy.setHorizontalStretch(0);
policy.setVerticalStretch(0);
policy.setHeightForWidth(false);
m_basketStatus->setSizePolicy(policy);
addWidget(m_basketStatus, 1, false); // Fit all extra space and is hiddable
} else
m_basketStatus = static_cast<QLabel*>(lst.at(0));
lst.clear();
m_selectionStatus = new QLabel(i18n("Loading..."), parent);
addWidget(m_selectionStatus, 0, true);
m_lockStatus = new QLabel(0/*this*/);
m_lockStatus->setMinimumSize(18, 18);
m_lockStatus->setAlignment(Qt::AlignCenter);
// addWidget( m_lockStatus, 0, true );
m_lockStatus->installEventFilter(this);
m_savedStatusPixmap = SmallIcon("document-save");
m_savedStatus = new QLabel(parent);
m_savedStatus->setPixmap(m_savedStatusPixmap);
m_savedStatus->setFixedSize(m_savedStatus->sizeHint());
m_savedStatus->clear();
//m_savedStatus->setPixmap(m_savedStatusIconSet.pixmap(QIconSet::Small, QIconSet::Disabled));
//m_savedStatus->setEnabled(false);
addWidget(m_savedStatus, 0, true);
m_savedStatus->setToolTip("<p>" + i18n("Shows if there are changes that have not yet been saved."));
}
void BasketStatusBar::postStatusbarMessage(const QString& text)
{
if (statusBar())
statusBar()->showMessage(text, 2000);
}
void BasketStatusBar::setStatusText(const QString &txt)
{
if (m_basketStatus && m_basketStatus->text() != txt)
m_basketStatus->setText(txt);
}
void BasketStatusBar::setStatusBarHint(const QString &hint)
{
if (hint.isEmpty())
updateStatusBarHint();
else
setStatusText(hint);
}
void BasketStatusBar::updateStatusBarHint()
{
QString message = "";
if (Global::bnpView->currentBasket()->isDuringDrag())
message = i18n("Ctrl+drop: copy, Shift+drop: move, Shift+Ctrl+drop: link.");
// Too much noise information:
// else if (currentBasket()->inserterShown() && currentBasket()->inserterSplit() && !currentBasket()->inserterGroup())
// message = i18n("Click to insert a note, right click for more options. Click on the right of the line to group instead of insert.");
// else if (currentBasket()->inserterShown() && currentBasket()->inserterSplit() && currentBasket()->inserterGroup())
// message = i18n("Click to group a note, right click for more options. Click on the left of the line to group instead of insert.");
else if (Global::debugWindow)
message = "DEBUG: " + Global::bnpView->currentBasket()->folderName();
setStatusText(message);
}
void BasketStatusBar::setLockStatus(bool isLocked)
{
if (!m_lockStatus)
return;
if (isLocked) {
m_lockStatus->setPixmap(SmallIcon("encrypted.png"));
m_lockStatus->setToolTip(i18n(
"<p>This basket is <b>locked</b>.<br>Click to unlock it.</p>").replace(" ", " "));
} else {
m_lockStatus->clear();
m_lockStatus->setToolTip(i18n(
"<p>This basket is <b>unlocked</b>.<br>Click to lock it.</p>").replace(" ", " "));
}
}
void BasketStatusBar::setSelectionStatus(const QString &s)
{
if (m_selectionStatus)
m_selectionStatus->setText(s);
}
void BasketStatusBar::setUnsavedStatus(bool isUnsaved)
{
if (!m_savedStatus)
return;
if (isUnsaved) {
if (m_savedStatus->pixmap() == 0)
m_savedStatus->setPixmap(m_savedStatusPixmap);
} else
m_savedStatus->clear();
}
bool BasketStatusBar::eventFilter(QObject * obj, QEvent * event)
{
if (obj == m_lockStatus && event->type() == QEvent::MouseButtonPress) {
QMouseEvent * mevent = dynamic_cast<QMouseEvent *>(event);
if (mevent->button() & Qt::LeftButton) {
Global::bnpView->lockBasket();
return true;
} else {
return QObject::eventFilter(obj, event); // standard event processing
}
}
return QObject::eventFilter(obj, event); // standard event processing
}