kexi

kexistatusbar.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and,or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 
00019    Loosely based on kdevelop/src/statusbar.cpp
00020    Copyright (C) 2001 by Bernd Gehrmann <bernd@kdevelop.org>
00021 */
00022 
00023 #include "kexistatusbar.h"
00024 
00025 #include <qlayout.h>
00026 #include <qlineedit.h>
00027 #include <qpainter.h>
00028 #include <qtimer.h>
00029 #include <qfontmetrics.h>
00030 
00031 #include <kdebug.h>
00032 #include <kglobalsettings.h>
00033 #include <klocale.h>
00034 #include <kparts/part.h>
00035 
00036 #if KexiStatusBar_KTEXTEDITOR_USED
00037 #include <ktexteditor/viewcursorinterface.h>
00038 #include <ktexteditor/viewstatusmsginterface.h>
00039 #endif
00040 
00041 KexiStatusBar::KexiStatusBar(QWidget *parent, const char *name)
00042     : KStatusBar(parent, name)
00043 #if KexiStatusBar_KTEXTEDITOR_USED
00044     , m_cursorIface(0)
00045 #endif
00046     , m_activePart(0)
00047 {
00048     int id = 0;
00049     m_msgID = id++;
00050     insertItem("", m_msgID, 1, true);
00051 
00052     m_readOnlyID = id++;
00053     insertFixedItem(i18n("Read only"), m_readOnlyID, true);
00054     setReadOnlyFlag(false);
00055 
00056 // @todo
00057 //  connect(PartController::getInstance(), SIGNAL(activePartChanged(KParts::Part*)),
00058 //      this, SLOT(activePartChanged(KParts::Part*)));
00059 
00061 }
00062 
00063 
00064 KexiStatusBar::~KexiStatusBar()
00065 {
00066 }
00067 
00068 void KexiStatusBar::activePartChanged(KParts::Part *part)
00069 {
00070     if ( m_activePart && m_activePart->widget() )
00071         disconnect( m_activePart->widget(), 0, this, 0 );
00072 
00073     m_activePart = part;
00074 #if KexiStatusBar_KTEXTEDITOR_USED
00075     m_cursorIface = 0;
00076     m_viewmsgIface = 0;
00077 // @todo
00078     if (part && part->widget()) {
00079         if ((m_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget()))) {
00080             connect( part->widget(), SIGNAL( viewStatusMsg( const QString & ) ),
00081                 this, SLOT( setStatus( const QString & ) ) );
00082 
00083 #  if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00084             changeItem(m_map[ m_activePart ], m_msgID);
00085 //          m_status->setText( m_map[ m_activePart ] );
00086 #  endif
00087         }
00088         else if ((m_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget()))) {
00089             connect(part->widget(), SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
00090             cursorPositionChanged();
00091         }
00092         else {
00093             // we can't produce any status data, hide the status box
00094             changeItem("", m_msgID);
00095         }
00096     }
00097 #endif
00098 }
00099 
00100 
00101 void KexiStatusBar::cursorPositionChanged()
00102 {
00103 #if KexiStatusBar_KTEXTEDITOR_USED
00104   if (m_cursorIface)
00105   {
00106     uint line, col;
00107     m_cursorIface->cursorPosition(&line, &col);
00108     setCursorPosition(line, col);
00109   }
00110 #endif
00111 }
00112 
00113 void KexiStatusBar::setStatus(const QString &str)
00114 {
00115     kdDebug() << "KexiStatusBar::setStatus(" << str << ")" << endl;
00116 //  m_status->setText(str);
00117     changeItem(str, m_msgID);
00118 
00119 #if defined(KDE_MAKE_VERSION)
00120 # if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00121     m_map[m_activePart] = str;
00122 # endif
00123 #endif
00124 }
00125 
00126 void KexiStatusBar::setCursorPosition(int line, int col)
00127 {
00128 //  m_status->setText(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col));
00129     changeItem(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col), m_msgID);
00130 }
00131 
00132 /*void KexiStatusBar::addWidget ( QWidget *widget, int stretch, bool permanent)
00133 {
00134     KStatusBar::addWidget(widget,stretch,permanent);
00135 
00136     if(widget->sizeHint().height() + 4 > height())
00137         setFixedHeight(widget->sizeHint().height() + 4);
00138 }*/
00139 
00140 void KexiStatusBar::setReadOnlyFlag(bool readOnly)
00141 {
00142     changeItem(readOnly ? i18n("Read only") : QString::null, m_readOnlyID);
00143 }
00144 
00145 #include "kexistatusbar.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys