Updated the README file with some contributor tips.
[basket4.git] / src / basketstatusbar.cpp
blob4bb0424c10db7c4dbe58acd0a476799121158fbf
1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
3 * slaout@linux62.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <kparts/statusbarextension.h>
22 #include <kstatusbar.h>
23 #include <klocale.h>
24 #include <kdebug.h>
25 #include <qlabel.h>
26 #include <qobject.h>
27 #include "basketstatusbar.h"
28 #include "clickablelabel.h"
29 #include "global.h"
30 #include "bnpview.h"
31 #include "basket.h"
32 #include "tools.h"
33 #include <kiconloader.h>
34 #include <qtooltip.h>
36 BasketStatusBar::BasketStatusBar(KStatusBar *bar)
37 : m_bar(bar), m_extension(0), m_selectionStatus(0), m_lockStatus(0), m_basketStatus(0), m_savedStatus(0)
41 BasketStatusBar::BasketStatusBar(KParts::StatusBarExtension *extension)
42 : m_bar(0), m_extension(extension), m_selectionStatus(0), m_lockStatus(0), m_basketStatus(0), m_savedStatus(0)
46 BasketStatusBar::~BasketStatusBar()
48 //delete m_extension;
51 KStatusBar *BasketStatusBar::statusBar () const
53 if(m_extension)
54 return m_extension->statusBar();
55 else
56 return m_bar;
59 void BasketStatusBar::addWidget(QWidget * widget, int stretch, bool permanent)
61 if(m_extension)
62 m_extension->addStatusBarItem(widget, stretch, permanent);
63 else
64 m_bar->addWidget(widget, stretch, permanent);
67 void BasketStatusBar::setupStatusBar()
69 QWidget* parent = statusBar();
70 QObjectList lst = parent->queryList("KRSqueezedTextLabel");
72 //Tools::printChildren(parent);
73 if(lst->count() == 0)
75 m_basketStatus = new QLabel(parent);
76 m_basketStatus->setSizePolicy( QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored, 0, 0, false) );
77 addWidget( m_basketStatus, 1, false ); // Fit all extra space and is hiddable
79 else
80 m_basketStatus = static_cast<QLabel*>(lst->at(0));
81 delete lst;
83 m_selectionStatus = new QLabel(i18n("Loading..."), parent);
84 addWidget( m_selectionStatus, 0, true );
86 m_lockStatus = new ClickableLabel(0/*this*/);
87 m_lockStatus->setMinimumSize(18, 18);
88 m_lockStatus->setAlignment(Qt::AlignCenter);
89 // addWidget( m_lockStatus, 0, true );
90 connect( m_lockStatus, SIGNAL(clicked()), Global::bnpView, SLOT(lockBasket()) );
92 m_savedStatusPixmap = SmallIcon("filesave");
93 m_savedStatus = new QLabel(parent);
94 m_savedStatus->setPixmap(m_savedStatusPixmap);
95 m_savedStatus->setFixedSize(m_savedStatus->sizeHint());
96 m_savedStatus->clear();
97 //m_savedStatus->setPixmap(m_savedStatusIconSet.pixmap(QIconSet::Small, QIconSet::Disabled));
98 //m_savedStatus->setEnabled(false);
99 addWidget( m_savedStatus, 0, true );
100 QToolTip::add(m_savedStatus, "<p>" + i18n("Shows if there are changes that have not yet been saved."));
103 void BasketStatusBar::postStatusbarMessage(const QString& text)
105 if(statusBar())
106 statusBar()->message(text, 2000);
109 void BasketStatusBar::setStatusText(const QString &txt)
111 if(m_basketStatus && m_basketStatus->text() != txt)
112 m_basketStatus->setText(txt);
115 void BasketStatusBar::setStatusBarHint(const QString &hint)
117 if (hint.isEmpty())
118 updateStatusBarHint();
119 else
120 setStatusText(hint);
123 void BasketStatusBar::updateStatusBarHint()
125 QString message = "";
127 if (Global::bnpView->currentBasket()->isDuringDrag())
128 message = i18n("Ctrl+drop: copy, Shift+drop: move, Shift+Ctrl+drop: link.");
129 // Too much noise information:
130 // else if (currentBasket()->inserterShown() && currentBasket()->inserterSplit() && !currentBasket()->inserterGroup())
131 // message = i18n("Click to insert a note, right click for more options. Click on the right of the line to group instead of insert.");
132 // else if (currentBasket()->inserterShown() && currentBasket()->inserterSplit() && currentBasket()->inserterGroup())
133 // message = i18n("Click to group a note, right click for more options. Click on the left of the line to group instead of insert.");
134 else if (Global::debugWindow)
135 message = "DEBUG: " + Global::bnpView->currentBasket()->folderName();
137 setStatusText(message);
140 void BasketStatusBar::setLockStatus(bool isLocked)
142 if(!m_lockStatus)
143 return;
145 if (isLocked) {
146 m_lockStatus->setPixmap(SmallIcon("encrypted.png"));
147 QToolTip::add(m_lockStatus, i18n(
148 "<p>This basket is <b>locked</b>.<br>Click to unlock it.</p>").replace(" ", "&nbsp;") );
149 // QToolTip::add(m_lockStatus, i18n("This basket is locked.\nClick to unlock it."));
150 } else {
151 m_lockStatus->clear();
152 QToolTip::add(m_lockStatus, i18n(
153 "<p>This basket is <b>unlocked</b>.<br>Click to lock it.</p>").replace(" ", "&nbsp;") );
154 // QToolTip::add(m_lockStatus, i18n("This basket is unlocked.\nClick to lock it."));
158 void BasketStatusBar::setSelectionStatus(const QString &s)
160 if (m_selectionStatus)
161 m_selectionStatus->setText(s);
164 void BasketStatusBar::setUnsavedStatus(bool isUnsaved)
166 if (!m_savedStatus)
167 return;
169 if (isUnsaved) {
170 if (m_savedStatus->pixmap() == 0)
171 m_savedStatus->setPixmap(m_savedStatusPixmap);
172 } else
173 m_savedStatus->clear();
176 #include "basketstatusbar.moc"