statusbar.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qlayout.h>
00013 #include <qlineedit.h>
00014 #include <qpainter.h>
00015 #include <qtimer.h>
00016 #include <qfontmetrics.h>
00017
00018 #include <kdebug.h>
00019 #include <kglobalsettings.h>
00020 #include <klocale.h>
00021 #include <kparts/part.h>
00022 #include <ktexteditor/viewcursorinterface.h>
00023 #include <kdeversion.h>
00024
00025 #if defined(KDE_MAKE_VERSION)
00026 # if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
00027 #include <ktexteditor/viewstatusmsginterface.h>
00028 # endif
00029 #endif
00030
00031 #include "statusbar.h"
00032 #include "partcontroller.h"
00033
00034 KDevStatusBar::KDevStatusBar(QWidget *parent, const char *name)
00035 : KStatusBar(parent, name), _cursorIface(0), _activePart(0)
00036 {
00037 QWidget * w = new QWidget( this );
00038 addWidget( w, 1, true );
00039 w->hide();
00040
00041 _status = new QLabel( this );
00042 _status->setMinimumWidth(_status->fontMetrics().width("Line: XXXXX Col: XXX OVR NORM * "));
00043 _status->setAlignment(QWidget::AlignCenter);
00044 addWidget(_status, 0, true);
00045
00046 connect(PartController::getInstance(), SIGNAL(activePartChanged(KParts::Part*)),
00047 this, SLOT(activePartChanged(KParts::Part*)));
00048 }
00049
00050
00051 KDevStatusBar::~KDevStatusBar()
00052 {}
00053
00054 void KDevStatusBar::activePartChanged(KParts::Part *part)
00055 {
00056 if ( _activePart && _activePart->widget() )
00057 disconnect( _activePart->widget(), 0, this, 0 );
00058
00059 _activePart = part;
00060 _cursorIface = 0;
00061 _viewmsgIface = 0;
00062
00063 if (part && part->widget())
00064 {
00065 if ((_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget())))
00066 {
00067 connect( part->widget(), SIGNAL( viewStatusMsg( const QString & ) ),
00068 this, SLOT( setStatus( const QString & ) ) );
00069
00070 _status->show();
00071 }
00072 else if ((_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget())))
00073 {
00074 connect(part->widget(), SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
00075
00076 _status->show();
00077 cursorPositionChanged();
00078 }
00079 else
00080 {
00081
00082 _status->hide();
00083 }
00084 }
00085 }
00086
00087 void KDevStatusBar::cursorPositionChanged()
00088 {
00089 if (_cursorIface)
00090 {
00091 uint line, col;
00092 _cursorIface->cursorPosition(&line, &col);
00093 setCursorPosition(line, col);
00094 }
00095 }
00096
00097 void KDevStatusBar::setStatus(const QString &str)
00098 {
00099 _status->setText(str);
00100 }
00101
00102
00103 void KDevStatusBar::setCursorPosition(int line, int col)
00104 {
00105 _status->setText(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col));
00106 }
00107
00108 void KDevStatusBar::addWidget ( QWidget *widget, int stretch, bool permanent)
00109 {
00110 KStatusBar::addWidget(widget,stretch,permanent);
00111
00112 if(widget->sizeHint().height() + 4 > height())
00113 setFixedHeight(widget->sizeHint().height() + 4);
00114 }
00115
00116 #include "statusbar.moc"
This file is part of the documentation for KDevelop Version 3.1.2.