1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
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. *
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. *
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>
27 #include "basketstatusbar.h"
28 #include "clickablelabel.h"
33 #include <kiconloader.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()
51 KStatusBar
*BasketStatusBar::statusBar () const
54 return m_extension
->statusBar();
59 void BasketStatusBar::addWidget(QWidget
* widget
, int stretch
, bool permanent
)
62 m_extension
->addStatusBarItem(widget
, stretch
, permanent
);
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);
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
80 m_basketStatus
= static_cast<QLabel
*>(lst
->at(0));
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
)
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
)
118 updateStatusBarHint();
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
)
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(" ", " ") );
149 // QToolTip::add(m_lockStatus, i18n("This basket is locked.\nClick to unlock it."));
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(" ", " ") );
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
)
170 if (m_savedStatus
->pixmap() == 0)
171 m_savedStatus
->setPixmap(m_savedStatusPixmap
);
173 m_savedStatus
->clear();
176 #include "basketstatusbar.moc"