aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2014-01-21 12:56:37 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2014-01-21 12:56:43 (GMT)
commit2d0f9881d872ec5fbba6dd64a58a00cb98966d35 (patch)
tree429d7c562141605589a29c8fb08ac8467f5de6a1
parent754f23797b176422875c846522e1404618b77c13 (diff)
integrate a decent statusbar
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/view/katestatusbar.cpp175
-rw-r--r--src/view/katestatusbar.h70
-rw-r--r--src/view/kateview.cpp7
-rw-r--r--src/view/kateview.h7
-rw-r--r--src/view/kateviewhelpers.cpp12
6 files changed, 268 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ca06758..761ec5c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -125,6 +125,7 @@ view/katemessagewidget.cpp
view/katefadeeffect.cpp
view/kateanimation.cpp
view/katetextanimation.cpp
+view/katestatusbar.cpp
# vi input mode
vimode/kateviinputmodemanager.cpp
diff --git a/src/view/katestatusbar.cpp b/src/view/katestatusbar.cpp
new file mode 100644
index 0000000..e301400
--- /dev/null
+++ b/src/view/katestatusbar.cpp
@@ -0,0 +1,175 @@
+/* This file is part of the KDE and the Kate project
+ *
+ * Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "katestatusbar.h"
+
+#include <KIconUtils>
+#include <KLocalizedString>
+
+#include <QVBoxLayout>
+
+KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view)
+ : KateViewBarWidget(false)
+ , m_view(view)
+ , m_statusBar(new QStatusBar(centralWidget()))
+{
+ /**
+ * just add our status bar to central widget, full sized
+ */
+ QVBoxLayout *topLayout = new QVBoxLayout(centralWidget());
+ topLayout->setMargin(0);
+ topLayout->addWidget(m_statusBar);
+
+ QString lineColText = i18n(" Line: %1 Col: %2 ", QLocale().toString(4444), QLocale().toString(44));
+
+ m_lineColLabel = new QLabel( m_statusBar );
+ m_lineColLabel->setMinimumWidth( m_lineColLabel->fontMetrics().width( lineColText ) );
+ m_statusBar->addWidget( m_lineColLabel, 0 );
+ m_lineColLabel->installEventFilter( this );
+
+ m_modifiedLabel = new QLabel( m_statusBar );
+ m_modifiedLabel->setFixedSize( 16, 16 );
+ m_statusBar->addWidget( m_modifiedLabel, 0 );
+ m_modifiedLabel->setAlignment( Qt::AlignCenter );
+ m_modifiedLabel->installEventFilter( this );
+
+ m_selectModeLabel = new QLabel( i18n(" LINE "), m_statusBar );
+ m_statusBar->addWidget( m_selectModeLabel, 0 );
+ m_selectModeLabel->setAlignment( Qt::AlignCenter );
+ m_selectModeLabel->installEventFilter( this );
+
+ m_insertModeLabel = new QLabel( i18n(" INS "), m_statusBar );
+ m_statusBar->addWidget( m_insertModeLabel, 0 );
+ m_insertModeLabel->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
+ m_insertModeLabel->installEventFilter( this );
+
+ m_infoLabel = new KSqueezedTextLabel( m_statusBar );
+ m_statusBar->addPermanentWidget( m_infoLabel, 1 );
+ m_infoLabel->setTextFormat(Qt::PlainText);
+ m_infoLabel->setMinimumSize( 0, 0 );
+ m_infoLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
+ m_infoLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
+ m_infoLabel->installEventFilter( this );
+
+
+ m_encodingLabel = new QLabel( QString(), m_statusBar );
+ m_statusBar->addPermanentWidget( m_encodingLabel, 0 );
+ m_encodingLabel->setAlignment( Qt::AlignCenter );
+ m_encodingLabel->installEventFilter( this );
+
+#ifdef Q_WS_MAC
+ m_statusBar->setSizeGripEnabled( false );
+ m_statusBar->addPermanentWidget( new QSizeGrip( m_statusBar ) );
+#endif
+
+ installEventFilter( m_statusBar );
+ m_modPm = QIcon::fromTheme(QStringLiteral("document-save")).pixmap(16);
+ m_modDiscPm = QIcon::fromTheme(QStringLiteral("dialog-warning")).pixmap(16);
+ QIcon icon = KIconUtils::addOverlay(QIcon::fromTheme(QStringLiteral("document-save")),
+ QIcon::fromTheme(QStringLiteral("emblem-important")),
+ Qt::TopLeftCorner);
+ m_modmodPm = icon.pixmap(16);
+
+ // signals for the statusbar
+ connect(m_view, SIGNAL(cursorPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), this, SLOT(cursorPositionChanged()));
+ connect(m_view, SIGNAL(viewModeChanged(KTextEditor::View*)), this, SLOT(viewModeChanged()));
+ connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(selectionChanged()));
+ connect(m_view, SIGNAL(informationMessage(KTextEditor::View*,QString)), this, SLOT(informationMessage(KTextEditor::View*,QString)));
+ connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(modifiedChanged()));
+ connect(m_view->document(), SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)), this, SLOT(modifiedChanged()) );
+ connect(m_view->document(), SIGNAL(configChanged()), this, SLOT(documentConfigChanged()));
+
+ updateStatus ();
+}
+
+bool KateStatusBar::eventFilter(QObject*, QEvent *e)
+{
+ if (e->type() == QEvent::MouseButtonPress)
+ {
+ m_view->setFocus();
+ return true;
+ }
+
+ return false;
+}
+
+void KateStatusBar::updateStatus ()
+{
+ viewModeChanged ();
+ cursorPositionChanged ();
+ selectionChanged ();
+ modifiedChanged ();
+ documentConfigChanged ();
+ m_infoLabel->clear ();
+}
+
+void KateStatusBar::viewModeChanged ()
+{
+ m_insertModeLabel->setText( QString::fromLatin1(" %1 ").arg (m_view->viewMode()) );
+}
+
+void KateStatusBar::cursorPositionChanged ()
+{
+ KTextEditor::Cursor position (m_view->cursorPositionVirtual());
+
+ m_lineColLabel->setText(
+ i18n(
+ " Line: %1 of %2 Col: %3 "
+ , QLocale().toString(position.line() + 1)
+ , m_view->document()->lines()
+ , QLocale().toString(position.column() + 1)
+ )
+ );
+}
+
+void KateStatusBar::selectionChanged ()
+{
+ m_selectModeLabel->setText( m_view->blockSelection() ? i18n(" BLOCK ") : i18n(" LINE ") );
+}
+
+void KateStatusBar::informationMessage (KTextEditor::View *, const QString &message)
+{
+ m_infoLabel->setText( message );
+
+ // timer to reset this after 4 seconds
+ QTimer::singleShot(4000, this, SLOT(updateStatus()));
+}
+
+void KateStatusBar::modifiedChanged()
+{
+ bool mod = m_view->document()->isModified();
+
+ bool modOnHD = false;//FIXME KF5 info && info->modifiedOnDisc;
+
+ m_modifiedLabel->setPixmap(
+ mod ?
+ modOnHD ?
+ m_modmodPm :
+ m_modPm :
+ modOnHD ?
+ m_modDiscPm :
+ QPixmap()
+ );
+}
+
+void KateStatusBar::documentConfigChanged ()
+{
+ m_encodingLabel->setText( QString::fromLatin1(" %1 ").arg (m_view->document()->encoding()) );
+}
diff --git a/src/view/katestatusbar.h b/src/view/katestatusbar.h
new file mode 100644
index 0000000..3afc6ec
--- /dev/null
+++ b/src/view/katestatusbar.h
@@ -0,0 +1,70 @@
+/* This file is part of the KDE and the Kate project
+ *
+ * Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KATE_STATUS_BAR_H
+#define KATE_STATUS_BAR_H
+
+#include "kateview.h"
+#include "kateviewhelpers.h"
+
+#include <KSqueezedTextLabel>
+
+#include <QLabel>
+#include <QPixmap>
+#include <QStatusBar>
+
+class KateStatusBar : public KateViewBarWidget
+{
+ Q_OBJECT
+
+public:
+ explicit KateStatusBar(KTextEditor::ViewPrivate *view);
+
+public Q_SLOTS:
+ void updateStatus ();
+
+ void viewModeChanged ();
+
+ void cursorPositionChanged ();
+
+ void selectionChanged ();
+
+ void modifiedChanged();
+
+ void documentConfigChanged ();
+
+ void informationMessage (KTextEditor::View *view, const QString &message);
+
+protected:
+ virtual bool eventFilter (QObject*, QEvent *);
+
+private:
+ KTextEditor::ViewPrivate *const m_view;
+ QStatusBar *const m_statusBar;
+ QLabel* m_lineColLabel;
+ QLabel* m_modifiedLabel;
+ QLabel* m_insertModeLabel;
+ QLabel* m_selectModeLabel;
+ QLabel* m_encodingLabel;
+ KSqueezedTextLabel* m_infoLabel;
+ QPixmap m_modPm, m_modDiscPm, m_modmodPm;
+};
+
+#endif
diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp
index 3ca4fe1..e62bd65 100644
--- a/src/view/kateview.cpp
+++ b/src/view/kateview.cpp
@@ -57,6 +57,7 @@
#include "katetemplatehandler.h"
#include "katepartdebug.h"
#include "printing/kateprinter.h"
+#include "katestatusbar.h"
#include <ktexteditor/messageinterface.h>
@@ -218,6 +219,12 @@ KTextEditor::ViewPrivate::ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget
m_vBox->addWidget(m_bottomViewBar);
}
+ /**
+ * create the status bar of this view
+ */
+ m_statusBar = new KateStatusBar(this);
+ bottomViewBar()->addPermanentBarWidget(m_statusBar);
+
// add layout for floating message widgets to KateViewInternal
m_notificationLayout = new QVBoxLayout(m_viewInternal);
m_notificationLayout->setContentsMargins(20, 20, 20, 20);
diff --git a/src/view/kateview.h b/src/view/kateview.h
index 55b0efb..2016e78 100644
--- a/src/view/kateview.h
+++ b/src/view/kateview.h
@@ -64,6 +64,7 @@ class KateDictionaryBar;
class KateSpellingMenu;
class KateMessageWidget;
class KateIconBorder;
+class KateStatusBar;
class KToggleAction;
class KSelectAction;
@@ -933,6 +934,12 @@ private:
public Q_SLOTS:
virtual bool print();
virtual void printPreview();
+
+private:
+ /**
+ * the status bar of this view
+ */
+ KateStatusBar *m_statusBar;
};
}
diff --git a/src/view/kateviewhelpers.cpp b/src/view/kateviewhelpers.cpp
index 546ace5..6768d06 100644
--- a/src/view/kateviewhelpers.cpp
+++ b/src/view/kateviewhelpers.cpp
@@ -2424,7 +2424,9 @@ void KateViewBar::showBarWidget(KateViewBarWidget *barWidget)
// if we have any permanent widget, bar is always visible,
// no need to show it
- if (!m_permanentBarWidget) {
+ if (m_permanentBarWidget) {
+ m_permanentBarWidget->hide();
+ } else {
setViewBarVisible(true);
}
}
@@ -2442,9 +2444,11 @@ void KateViewBar::hideCurrentBarWidget()
}
m_stack->hide();
- // if we have any permanent widget, bar is always visible,
- // no need to hide it
- if (!m_permanentBarWidget) {
+ // if we have any permanent widget, make it visible again
+ if (m_permanentBarWidget) {
+ m_permanentBarWidget->show ();
+ } else {
+ // else: hide the bar
setViewBarVisible(false);
}