src/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 StatusBar::StatusBar(
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
00050 }
00051
00052
00053 StatusBar::~StatusBar()
00054 {}
00055
00056 void StatusBar::activePartChanged(
KParts::Part *part)
00057 {
00058
if (
_activePart &&
_activePart->
widget() )
00059 disconnect(
_activePart->
widget(), 0,
this, 0 );
00060
00061
_activePart = part;
00062
_cursorIface = 0;
00063
#if defined(KDE_MAKE_VERSION)
00064
# if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
00065
_viewmsgIface = 0;
00066
# endif
00067
#endif
00068
00069
if (part && part->widget())
00070 {
00071
00072
#if defined(KDE_MAKE_VERSION)
00073
# if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
00074
if ((_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget())))
00075 {
00076 connect( part->widget(), SIGNAL( viewStatusMsg(
const QString & ) ),
00077
this, SLOT(
setStatus(
const QString & ) ) );
00078
00079
# if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00080
_status->setText( _map[
_activePart ] );
00081
# endif
00082
00083
_status->show();
00084 }
00085
else
00086
# endif
00087
#endif
00088
if ((
_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget())))
00089 {
00090 connect(part->widget(), SIGNAL(
cursorPositionChanged()),
this, SLOT(
cursorPositionChanged()));
00091
00092
_status->show();
00093
cursorPositionChanged();
00094 }
00095
else
00096 {
00097
00098
_status->hide();
00099 }
00100 }
00101 }
00102
00103
00104 void StatusBar::cursorPositionChanged()
00105 {
00106
if (
_cursorIface)
00107 {
00108 uint line, col;
00109
_cursorIface->
cursorPosition(&line, &col);
00110
setCursorPosition(line, col);
00111 }
00112 }
00113
00114 void StatusBar::setStatus(
const QString &str)
00115 {
00116
_status->setText(str);
00117
00118
#if defined(KDE_MAKE_VERSION)
00119
# if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00120
_map[
_activePart] = str;
00121
# endif
00122
#endif
00123
}
00124
00125
00126 void StatusBar::setCursorPosition(
int line,
int col)
00127 {
00128
_status->setText(i18n(
" Line: %1 Col: %2 ").arg(line+1).arg(col));
00129 }
00130
00131 void StatusBar::addWidget (
QWidget *widget,
int stretch,
bool permanent)
00132 {
00133 KStatusBar::addWidget(widget,stretch,permanent);
00134
00135
if(widget->sizeHint().height() + 4 > height())
00136 setFixedHeight(widget->sizeHint().height() + 4);
00137 }
00138
00139
#include "statusbar.moc"
This file is part of the documentation for KDevelop Version 3.0.4.