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 #ifdef KEXI_FUTURE_FEATURES
00053     m_readOnlyID = id++;
00054     insertFixedItem(futureI18n("Read only"), m_readOnlyID, true);
00055     setReadOnlyFlag(false);
00056 #endif
00057 
00058 // @todo
00059 //  connect(PartController::getInstance(), SIGNAL(activePartChanged(KParts::Part*)),
00060 //      this, SLOT(activePartChanged(KParts::Part*)));
00061 
00063 }
00064 
00065 
00066 KexiStatusBar::~KexiStatusBar()
00067 {
00068 }
00069 
00070 void KexiStatusBar::activePartChanged(KParts::Part *part)
00071 {
00072     if ( m_activePart && m_activePart->widget() )
00073         disconnect( m_activePart->widget(), 0, this, 0 );
00074 
00075     m_activePart = part;
00076 #if KexiStatusBar_KTEXTEDITOR_USED
00077     m_cursorIface = 0;
00078     m_viewmsgIface = 0;
00079 // @todo
00080     if (part && part->widget()) {
00081         if ((m_viewmsgIface = dynamic_cast<KTextEditor::ViewStatusMsgInterface*>(part->widget()))) {
00082             connect( part->widget(), SIGNAL( viewStatusMsg( const QString & ) ),
00083                 this, SLOT( setStatus( const QString & ) ) );
00084 
00085 #  if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00086             changeItem(m_map[ m_activePart ], m_msgID);
00087 //          m_status->setText( m_map[ m_activePart ] );
00088 #  endif
00089         }
00090         else if ((m_cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>(part->widget()))) {
00091             connect(part->widget(), SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
00092             cursorPositionChanged();
00093         }
00094         else {
00095             // we can't produce any status data, hide the status box
00096             changeItem("", m_msgID);
00097         }
00098     }
00099 #endif
00100 }
00101 
00102 
00103 void KexiStatusBar::cursorPositionChanged()
00104 {
00105 #if KexiStatusBar_KTEXTEDITOR_USED
00106   if (m_cursorIface)
00107   {
00108     uint line, col;
00109     m_cursorIface->cursorPosition(&line, &col);
00110     setCursorPosition(line, col);
00111   }
00112 #endif
00113 }
00114 
00115 void KexiStatusBar::setStatus(const QString &str)
00116 {
00117     kdDebug() << "KexiStatusBar::setStatus(" << str << ")" << endl;
00118 //  m_status->setText(str);
00119     changeItem(str, m_msgID);
00120 
00121 #if defined(KDE_MAKE_VERSION)
00122 # if KDE_VERSION < KDE_MAKE_VERSION(3,1,90)
00123     m_map[m_activePart] = str;
00124 # endif
00125 #endif
00126 }
00127 
00128 void KexiStatusBar::setCursorPosition(int line, int col)
00129 {
00130 //  m_status->setText(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col));
00131     changeItem(i18n(" Line: %1 Col: %2 ").arg(line+1).arg(col), m_msgID);
00132 }
00133 
00134 /*void KexiStatusBar::addWidget ( QWidget *widget, int stretch, bool permanent)
00135 {
00136     KStatusBar::addWidget(widget,stretch,permanent);
00137 
00138     if(widget->sizeHint().height() + 4 > height())
00139         setFixedHeight(widget->sizeHint().height() + 4);
00140 }*/
00141 
00142 void KexiStatusBar::setReadOnlyFlag(bool readOnly)
00143 {
00144 #ifdef KEXI_FUTURE_FEATURES
00145     changeItem(readOnly ? futureI18n("Read only") : QString::null, m_readOnlyID);
00146 #else
00147     Q_UNUSED(readOnly);
00148 #endif
00149 }
00150 
00151 #include "kexistatusbar.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys