Kate
katevimodebar.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00050
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
00091
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 }