summaryrefslogtreecommitdiffstats
path: root/kexi/main/kexistatusbar.cpp
blob: e4bfd5801fd0226968f994643d93fc330902ed96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* This file is part of the KDE project
   Copyright (C) 2003 Jaroslaw Staniek <[email protected]>

   This program is free software; you can redistribute it and,or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.

   Loosely based on tdevelop/src/statusbar.cpp
   Copyright (C) 2001 by Bernd Gehrmann <[email protected]>
*/

#include "kexistatusbar.h"

#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpainter.h>
#include <tqtimer.h>
#include <tqfontmetrics.h>

#include <kdebug.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kparts/part.h>

#if KexiStatusBar_KTEXTEDITOR_USED
#include <ktexteditor/viewcursorinterface.h>
#include <ktexteditor/viewstatusmsginterface.h>
#endif

KexiStatusBar::KexiStatusBar(TQWidget *parent, const char *name)
    : KStatusBar(parent, name)
#if KexiStatusBar_KTEXTEDITOR_USED
	, m_cursorIface(0)
#endif
	, m_activePart(0)
{
	int id = 0;
	m_msgID = id++;
	insertItem("", m_msgID, 1, true);

	m_readOnlyID = id++;
	insertFixedItem(i18n("Read only"), m_readOnlyID, true);
	setReadOnlyFlag(false);

// @todo
//	connect(PartController::getInstance(), TQT_SIGNAL(activePartChanged(KParts::Part*)),
//		this, TQT_SLOT(activePartChanged(KParts::Part*)));

	/// @todo remove parts from the map on PartRemoved() ?
}


KexiStatusBar::~KexiStatusBar()
{
}

void KexiStatusBar::activePartChanged(KParts::Part *part)
{
	if ( m_activePart && m_activePart->widget() )
		disconnect( m_activePart->widget(), 0, this, 0 );

	m_activePart = part;
#if KexiStatusBar_KTEXTEDITOR_USED
	m_cursorIface = 0;
	m_viewmsgIface = 0;
// @todo
	if (part && part->widget()) {
		if ((m_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget()))) {
			connect( part->widget(), TQT_SIGNAL( viewStatusMsg( const TQString & ) ),
				this, TQT_SLOT( settqStatus( const TQString & ) ) );

#  if TDE_VERSION < KDE_MAKE_VERSION(3,1,90)
			changeItem(m_map[ m_activePart ], m_msgID);
//			m_status->setText( m_map[ m_activePart ] );
#  endif
		}
		else if ((m_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget()))) {
			connect(part->widget(), TQT_SIGNAL(cursorPositionChanged()), this, TQT_SLOT(cursorPositionChanged()));
			cursorPositionChanged();
	    }
		else {
			// we can't produce any status data, hide the status box
			changeItem("", m_msgID);
		}
	}
#endif
}


void KexiStatusBar::cursorPositionChanged()
{
#if KexiStatusBar_KTEXTEDITOR_USED
  if (m_cursorIface)
  {
    uint line, col;
    m_cursorIface->cursorPosition(&line, &col);
    setCursorPosition(line, col);
  }
#endif
}

void KexiStatusBar::settqStatus(const TQString &str)
{
	kdDebug() << "KexiStatusBar::setStatus(" << str << ")" << endl;
//	m_status->setText(str);
	changeItem(str, m_msgID);

#if defined(KDE_MAKE_VERSION)
# if TDE_VERSION < KDE_MAKE_VERSION(3,1,90)
	m_map[m_activePart] = str;
# endif
#endif
}

void KexiStatusBar::setCursorPosition(int line, int col)
{
//	m_status->setText(i18n(" Line: %1 Col: %2 ").tqarg(line+1).tqarg(col));
	changeItem(i18n(" Line: %1 Col: %2 ").tqarg(line+1).tqarg(col), m_msgID);
}

/*void KexiStatusBar::addWidget ( TQWidget *widget, int stretch, bool permanent)
{
	KStatusBar::addWidget(widget,stretch,permanent);

	if(widget->tqsizeHint().height() + 4 > height())
		setFixedHeight(widget->tqsizeHint().height() + 4);
}*/

void KexiStatusBar::setReadOnlyFlag(bool readOnly)
{
	changeItem(readOnly ? i18n("Read only") : TQString(), m_readOnlyID);
}

#include "kexistatusbar.moc"