kexi

kexistatusbar.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and,or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18
19 Loosely based on tdevelop/src/statusbar.cpp
20 Copyright (C) 2001 by Bernd Gehrmann <bernd@kdevelop.org>
21*/
22
23#include "kexistatusbar.h"
24
25#include <tqlayout.h>
26#include <tqlineedit.h>
27#include <tqpainter.h>
28#include <tqtimer.h>
29#include <tqfontmetrics.h>
30
31#include <kdebug.h>
32#include <tdeglobalsettings.h>
33#include <tdelocale.h>
34#include <tdeparts/part.h>
35
36#if KexitStatusBar_KTEXTEDITOR_USED
37#include <tdetexteditor/viewcursorinterface.h>
38#include <tdetexteditor/viewstatusmsginterface.h>
39#endif
40
41KexitStatusBar::KexitStatusBar(TQWidget *parent, const char *name)
42 : KStatusBar(parent, name)
43#if KexitStatusBar_KTEXTEDITOR_USED
44 , m_cursorIface(0)
45#endif
46 , m_activePart(0)
47{
48 int id = 0;
49 m_msgID = id++;
50 insertItem("", m_msgID, 1, true);
51
52 m_readOnlyID = id++;
53 insertFixedItem(i18n("Read only"), m_readOnlyID, true);
54 setReadOnlyFlag(false);
55
56// @todo
57// connect(PartController::getInstance(), TQ_SIGNAL(activePartChanged(KParts::Part*)),
58// this, TQ_SLOT(activePartChanged(KParts::Part*)));
59
61}
62
63
64KexitStatusBar::~KexitStatusBar()
65{
66}
67
68void KexitStatusBar::activePartChanged(KParts::Part *part)
69{
70 if ( m_activePart && m_activePart->widget() )
71 disconnect( m_activePart->widget(), 0, this, 0 );
72
73 m_activePart = part;
74#if KexitStatusBar_KTEXTEDITOR_USED
75 m_cursorIface = 0;
76 m_viewmsgIface = 0;
77// @todo
78 if (part && part->widget()) {
79 if ((m_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget()))) {
80 connect( part->widget(), TQ_SIGNAL( viewStatusMsg( const TQString & ) ),
81 this, TQ_SLOT( setStatus( const TQString & ) ) );
82 }
83 else if ((m_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget()))) {
84 connect(part->widget(), TQ_SIGNAL(cursorPositionChanged()), this, TQ_SLOT(cursorPositionChanged()));
85 cursorPositionChanged();
86 }
87 else {
88 // we can't produce any status data, hide the status box
89 changeItem("", m_msgID);
90 }
91 }
92#endif
93}
94
95
96void KexitStatusBar::cursorPositionChanged()
97{
98#if KexitStatusBar_KTEXTEDITOR_USED
99 if (m_cursorIface)
100 {
101 uint line, col;
102 m_cursorIface->cursorPosition(&line, &col);
103 setCursorPosition(line, col);
104 }
105#endif
106}
107
108void KexitStatusBar::setStatus(const TQString &str)
109{
110 kdDebug() << "KexitStatusBar::setStatus(" << str << ")" << endl;
111// m_status->setText(str);
112 changeItem(str, m_msgID);
113}
114
115void KexitStatusBar::setCursorPosition(int line, int col)
116{
117// m_status->setText(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col));
118 changeItem(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col), m_msgID);
119}
120
121/*void KexitStatusBar::addWidget ( TQWidget *widget, int stretch, bool permanent)
122{
123 KStatusBar::addWidget(widget,stretch,permanent);
124
125 if(widget->sizeHint().height() + 4 > height())
126 setFixedHeight(widget->sizeHint().height() + 4);
127}*/
128
129void KexitStatusBar::setReadOnlyFlag(bool readOnly)
130{
131 changeItem(readOnly ? i18n("Read only") : TQString(), m_readOnlyID);
132}
133
134#include "kexistatusbar.moc"