delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqframestatusbar.cpp
blobb4fbc30ea7f4cba00e6dd0a6b7ada5d813548c01
1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Michael Reiher <michael.reiher@gmx.de>
3 Copyright 2007 David Faure <faure@kde.org>
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 Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "konqframestatusbar.h"
21 #include <kdebug.h>
22 #include "konqframe.h"
23 #include "konqview.h"
24 #include <kiconloader.h>
25 #include <QCheckBox>
26 #include <QPainter>
27 #include <QLabel>
28 #include <QMenu>
29 #include <QProgressBar>
30 #include <ksqueezedtextlabel.h>
31 #include <klocale.h>
32 #include <kactioncollection.h>
34 /**
35 * A CheckBox with a special paintEvent(). It looks like the
36 * unchecked radiobutton in b2k style if unchecked and contains a little
37 * anchor if checked.
39 class KonqCheckBox : public QCheckBox
41 //Q_OBJECT // for classname. not used, and needs a moc
42 public:
43 explicit KonqCheckBox(QWidget *parent=0)
44 : QCheckBox( parent ) {}
45 protected:
46 void paintEvent( QPaintEvent * );
49 #define DEFAULT_HEADER_HEIGHT 13
51 void KonqCheckBox::paintEvent( QPaintEvent * )
53 //static QPixmap indicator_anchor( UserIcon( "indicator_anchor" ) );
54 static QPixmap indicator_connect( UserIcon( "indicator_connect" ) );
55 static QPixmap indicator_noconnect( UserIcon( "indicator_noconnect" ) );
57 QPainter p(this);
59 if (isChecked() || isDown())
60 p.drawPixmap(0,0,indicator_connect);
61 else
62 p.drawPixmap(0,0,indicator_noconnect);
65 KonqFrameStatusBar::KonqFrameStatusBar( KonqFrame *_parent )
66 : KStatusBar( _parent ),
67 m_pParentKonqFrame( _parent )
69 setSizeGripEnabled( false );
71 m_led = new QLabel( this );
72 m_led->setAlignment( Qt::AlignCenter );
73 m_led->setSizePolicy(QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ));
74 addWidget( m_led, 0 ); // led (active view indicator)
75 m_led->hide();
77 m_pStatusLabel = new KSqueezedTextLabel( this );
78 m_pStatusLabel->setMinimumSize( 0, 0 );
79 m_pStatusLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
80 m_pStatusLabel->installEventFilter(this);
81 addWidget( m_pStatusLabel, 1 /*stretch*/ ); // status label
83 m_pLinkedViewCheckBox = new KonqCheckBox( this );
84 m_pLinkedViewCheckBox->setObjectName( "m_pLinkedViewCheckBox" );
85 m_pLinkedViewCheckBox->setFocusPolicy(Qt::NoFocus);
86 m_pLinkedViewCheckBox->setSizePolicy(QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ));
87 m_pLinkedViewCheckBox->setWhatsThis( i18n("Checking this box on at least two views sets those views as 'linked'. "
88 "Then, when you change directories in one view, the other views "
89 "linked with it will automatically update to show the current directory. "
90 "This is especially useful with different types of views, such as a "
91 "directory tree with an icon view or detailed view, and possibly a "
92 "terminal emulator window." ) );
93 addPermanentWidget( m_pLinkedViewCheckBox, 0 );
94 connect( m_pLinkedViewCheckBox, SIGNAL(toggled(bool)),
95 this, SIGNAL(linkedViewClicked(bool)) );
97 m_progressBar = new QProgressBar( this );
98 // Minimum width of QProgressBar::sizeHint depends on PM_ProgressBarChunkWidth which doesn't make sense;
99 // we don't want chunking but we want a reasonably-sized progressbar :)
100 m_progressBar->setMinimumWidth(150);
101 m_progressBar->setMaximumHeight(fontMetrics().height());
102 m_progressBar->hide();
103 addPermanentWidget( m_progressBar, 0 );
105 fontChange(QFont());
106 installEventFilter( this );
109 KonqFrameStatusBar::~KonqFrameStatusBar()
113 void KonqFrameStatusBar::fontChange(const QFont & /* oldFont */)
115 int h = fontMetrics().height();
116 if ( h < DEFAULT_HEADER_HEIGHT ) h = DEFAULT_HEADER_HEIGHT;
117 m_led->setFixedHeight( h + 2 );
118 m_progressBar->setFixedHeight( h + 2 );
119 // This one is important. Otherwise richtext messages make it grow in height.
120 m_pStatusLabel->setFixedHeight( h + 2 );
124 // I don't think this code _ever_ gets called!
125 // I don't want to remove it, though. :-)
126 void KonqFrameStatusBar::mousePressEvent( QMouseEvent* event )
128 QWidget::mousePressEvent( event );
129 if ( !m_pParentKonqFrame->childView()->isPassiveMode() )
131 emit clicked();
132 update();
135 //Blocks menu of custom status bar entries
136 //if (event->button()==RightButton)
137 // splitFrameMenu();
140 void KonqFrameStatusBar::splitFrameMenu()
142 KonqMainWindow * mw = m_pParentKonqFrame->childView()->mainWindow();
144 // We have to ship the remove view action ourselves,
145 // since this may not be the active view (passive view)
146 KAction actRemoveView(KIcon("view-close"), i18n("Close View"), 0);
147 actRemoveView.setObjectName("removethisview");
148 connect(&actRemoveView, SIGNAL(triggered(bool)), m_pParentKonqFrame, SLOT(slotRemoveView()));
149 actRemoveView.setEnabled( mw->mainViewsCount() > 1 || m_pParentKonqFrame->childView()->isToggleView() || m_pParentKonqFrame->childView()->isPassiveMode() );
151 // For the rest, we borrow them from the main window
152 // ###### might be not right for passive views !
153 KActionCollection *actionColl = mw->actionCollection();
155 QMenu menu;
157 menu.addAction( actionColl->action( "splitviewh" ) );
158 menu.addAction( actionColl->action( "splitviewv" ) );
159 menu.addSeparator();
160 menu.addAction( actionColl->action( "lock" ) );
161 menu.addAction( &actRemoveView );
163 menu.exec(QCursor::pos());
166 bool KonqFrameStatusBar::eventFilter(QObject* o, QEvent *e)
168 if (o == m_pStatusLabel && e->type()==QEvent::MouseButtonPress)
170 emit clicked();
171 update();
172 if ( static_cast<QMouseEvent *>(e)->button() == Qt::RightButton)
173 splitFrameMenu();
174 return true;
176 else if ( o == this && e->type() == QEvent::ApplicationPaletteChange )
178 //unsetPalette();
179 setPalette(QPalette());
180 updateActiveStatus();
181 return true;
184 return KStatusBar::eventFilter(o, e);
187 void KonqFrameStatusBar::message( const QString &msg )
189 // We don't use the message()/clear() mechanism of QStatusBar because
190 // it really looks ugly (the label border goes away, the active-view indicator
191 // is hidden...)
192 QString saveMsg = m_savedMessage;
193 slotDisplayStatusText( msg );
194 m_savedMessage = saveMsg;
197 void KonqFrameStatusBar::slotDisplayStatusText(const QString& text)
199 //kDebug(1202) << text;
200 m_pStatusLabel->setText(text);
201 m_savedMessage = text;
204 // ### TODO: was also used in kde3 for the signals from kactioncollection...
205 void KonqFrameStatusBar::slotClear()
207 slotDisplayStatusText( m_savedMessage );
210 void KonqFrameStatusBar::slotLoadingProgress( int percent )
212 if (percent == -1 || percent == 100) { // hide on error and on success
213 m_progressBar->hide();
214 } else {
215 m_progressBar->show();
218 m_progressBar->setValue(percent);
221 void KonqFrameStatusBar::slotSpeedProgress( int bytesPerSecond )
223 QString sizeStr;
225 if ( bytesPerSecond > 0 )
226 sizeStr = i18n( "%1/s", KIO::convertSize( bytesPerSecond ) );
227 else
228 sizeStr = i18n( "Stalled" );
230 slotDisplayStatusText( sizeStr ); // let's share the same label...
233 void KonqFrameStatusBar::slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *newOne)
235 if (newOne)
236 connect(newOne,SIGNAL(setStatusBarText(const QString &)),this,SLOT(slotDisplayStatusText(const QString&)));
237 slotDisplayStatusText( QString() );
240 void KonqFrameStatusBar::showActiveViewIndicator( bool b )
242 m_led->setVisible( b );
243 updateActiveStatus();
246 void KonqFrameStatusBar::showLinkedViewIndicator( bool b )
248 m_pLinkedViewCheckBox->setVisible( b );
251 void KonqFrameStatusBar::setLinkedView( bool b )
253 m_pLinkedViewCheckBox->blockSignals( true );
254 m_pLinkedViewCheckBox->setChecked( b );
255 m_pLinkedViewCheckBox->blockSignals( false );
258 void KonqFrameStatusBar::updateActiveStatus()
260 if ( m_led->isHidden() )
262 //unsetPalette();
263 setPalette(QPalette());
264 return;
267 bool hasFocus = m_pParentKonqFrame->isActivePart();
269 const QColor midLight = palette().midlight().color();
270 const QColor Mid = palette().mid().color();
271 QPalette palette;
272 palette.setColor(backgroundRole(), hasFocus ? midLight : Mid);
273 setPalette(palette);
275 static QPixmap indicator_viewactive( UserIcon( "indicator_viewactive" ) );
276 static QPixmap indicator_empty( UserIcon( "indicator_empty" ) );
277 m_led->setPixmap( hasFocus ? indicator_viewactive : indicator_empty );
280 #include "konqframestatusbar.moc"