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