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# if TDE_VERSION < TDE_MAKE_VERSION(3,1,90)
84 changeItem(m_map[ m_activePart ], m_msgID);
85// m_status->setText( m_map[ m_activePart ] );
86# endif
87 }
88 else if ((m_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget()))) {
89 connect(part->widget(), TQ_SIGNAL(cursorPositionChanged()), this, TQ_SLOT(cursorPositionChanged()));
90 cursorPositionChanged();
91 }
92 else {
93 // we can't produce any status data, hide the status box
94 changeItem("", m_msgID);
95 }
96 }
97#endif
98}
99
100
101void KexitStatusBar::cursorPositionChanged()
102{
103#if KexitStatusBar_KTEXTEDITOR_USED
104 if (m_cursorIface)
105 {
106 uint line, col;
107 m_cursorIface->cursorPosition(&line, &col);
108 setCursorPosition(line, col);
109 }
110#endif
111}
112
113void KexitStatusBar::setStatus(const TQString &str)
114{
115 kdDebug() << "KexitStatusBar::setStatus(" << str << ")" << endl;
116// m_status->setText(str);
117 changeItem(str, m_msgID);
118
119#if defined(TDE_MAKE_VERSION)
120# if TDE_VERSION < TDE_MAKE_VERSION(3,1,90)
121 m_map[m_activePart] = str;
122# endif
123#endif
124}
125
126void KexitStatusBar::setCursorPosition(int line, int col)
127{
128// m_status->setText(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col));
129 changeItem(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col), m_msgID);
130}
131
132/*void KexitStatusBar::addWidget ( TQWidget *widget, int stretch, bool permanent)
133{
134 KStatusBar::addWidget(widget,stretch,permanent);
135
136 if(widget->sizeHint().height() + 4 > height())
137 setFixedHeight(widget->sizeHint().height() + 4);
138}*/
139
140void KexitStatusBar::setReadOnlyFlag(bool readOnly)
141{
142 changeItem(readOnly ? i18n("Read only") : TQString(), m_readOnlyID);
143}
144
145#include "kexistatusbar.moc"