• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katevimodebar.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002  * Copyright (C) 2008 Dmitry Suzdalev <dimsuz@gmail.com>
00003  * Copyright (C) 2008 Erlend Hamberg <ehamberg@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) version 3.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "katevimodebar.h"
00022 #include "kateviinputmodemanager.h"
00023 #include "katevinormalmode.h"
00024 #include "katevivisualmode.h"
00025 #include "kateviinsertmode.h"
00026 
00027 #include <QtGui/QLabel>
00028 #include <QtGui/QHBoxLayout>
00029 #include <QTimer>
00030 #include <QTextDocument>
00031 
00032 #include "klocale.h"
00033 
00034 KateViModeBar::KateViModeBar(KateView* view, QWidget* parent)
00035 : KateViewBarWidget(false, view, parent),
00036   m_labelStatus(new QLabel(this)),
00037   m_labelMessage(new QLabel(this)),
00038   m_labelCommand(new QLabel(this)),
00039   m_timer(0)
00040 {
00041   QHBoxLayout *lay = qobject_cast<QHBoxLayout*>(layout());
00042   lay->addWidget(m_labelStatus);
00043   lay->addSpacing(30);
00044   lay->addWidget(m_labelMessage);
00045   lay->addStretch(1);
00046   lay->addWidget(m_labelCommand);
00047   lay->addSpacing(30);
00048 
00049   // otherwise the command will look 'jumpy' as new symbols are added to it
00050   // 50 pix should be enough i think
00051   m_labelCommand->setFixedWidth(50);
00052 
00053   m_labelStatus->setTextFormat(Qt::PlainText);
00054   m_labelCommand->setTextFormat(Qt::PlainText);
00055 }
00056 
00057 KateViModeBar::~KateViModeBar()
00058 {
00059   delete m_timer;
00060 }
00061 
00062 void KateViModeBar::updateViMode(ViMode mode)
00063 {
00064   m_labelStatus->setText(modeToString(mode));
00065 }
00066 
00067 void KateViModeBar::updatePartialCommand(const QString &cmd)
00068 {
00069   m_labelCommand->setText(cmd);
00070 }
00071 
00072 void KateViModeBar::showMessage(const QString &msg)
00073 {
00074   if ( m_timer ) {
00075     m_timer->stop();
00076   }
00077   m_labelMessage->setText(msg);
00078 }
00079 
00080 void KateViModeBar::showErrorMessage(const QString &msg)
00081 {
00082   if ( m_timer ) {
00083     m_timer->stop();
00084   }
00085   m_labelMessage->setText(QString("<font color=\"red\">")+Qt::escape(msg)+"</font>");
00086 }
00087 
00088 void KateViModeBar::clearMessage()
00089 {
00090   // don't clear the message right away, wait two seconds so the user will see the message even if
00091   // she presses a key right after getting the error message
00092   if ( !m_labelMessage->text().isEmpty() ) {
00093     if (!m_timer) {
00094       m_timer = new QTimer(this);
00095       connect(m_timer, SIGNAL(timeout()), this, SLOT(_clearMessage()));
00096       m_timer->setSingleShot(true);
00097       m_timer->setInterval(2000);
00098     }
00099 
00100     m_timer->start();
00101   }
00102 }
00103 
00104 void KateViModeBar::_clearMessage()
00105 {
00106   m_labelMessage->clear();
00107 }
00108 
00109 QString KateViModeBar::modeToString(ViMode mode) const
00110 {
00111   QString modeStr;
00112   switch (mode) {
00113     case InsertMode:
00114       modeStr = i18n("VI: INSERT MODE");
00115       break;
00116     case NormalMode:
00117       modeStr = i18n("VI: NORMAL MODE");
00118       break;
00119     case VisualMode:
00120       modeStr = i18n("VI: VISUAL");
00121       break;
00122     case VisualLineMode:
00123       modeStr = i18n("VI: VISUAL LINE");
00124       break;
00125   }
00126   return modeStr;
00127 }

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal