Index: src/view/katestatusbar.h =================================================================== --- src/view/katestatusbar.h +++ src/view/katestatusbar.h @@ -42,9 +42,23 @@ void setVisible(bool) override; }; +/** + * For convenience an own button class to ensure a unified look&feel. + * Should someone dislike the QPushButton at all could he change it + * to a e.g. QLabel subclass + */ +class StatusBarButton: public QPushButton +{ + Q_OBJECT +public: + explicit StatusBarButton(KateStatusBar *parent, const QString &text = QString()); + ~StatusBarButton() override; +}; + class KateStatusBar : public KateViewBarWidget { Q_OBJECT + friend class StatusBarButton; public: explicit KateStatusBar(KTextEditor::ViewPrivate *view); @@ -76,13 +90,13 @@ private: KTextEditor::ViewPrivate *const m_view; - QLabel *m_lineColLabel; + StatusBarButton *m_cursorPosition = nullptr; QLabel *m_wordCountLabel; - QToolButton *m_modifiedLabel; - QLabel *m_insertModeLabel; - QPushButton *m_mode; - QPushButton *m_encoding; - QPushButton *m_tabsIndent; + StatusBarButton *m_modified = nullptr; + StatusBarButton *m_inputMode = nullptr; + StatusBarButton *m_mode = nullptr; + StatusBarButton *m_encoding = nullptr; + StatusBarButton *m_tabsIndent = nullptr; KLocalizedString m_spacesOnly; KLocalizedString m_tabsOnly; KLocalizedString m_tabSpacesMixed; Index: src/view/katestatusbar.cpp =================================================================== --- src/view/katestatusbar.cpp +++ src/view/katestatusbar.cpp @@ -53,10 +53,22 @@ } //END menu +//BEGIN StatusBarButton +StatusBarButton::StatusBarButton(KateStatusBar *parent, const QString &text /*= QString()*/) + : QPushButton(text, parent) +{ + setFlat(true); + setFocusProxy(parent->m_view); +} + +StatusBarButton::~StatusBarButton() +{ +} +//END StatusBarButton + KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view) : KateViewBarWidget(false) , m_view(view) - , m_insertModeLabel(nullptr) , m_modifiedStatus(-1) , m_selectionMode(-1) , m_wordCounter(nullptr) @@ -76,15 +88,22 @@ */ topLayout->addSpacing(4); + /** + * show modification state of the document + * TODO Using a (StatusBar)Button is currently pointless but handy due to no "setIcon()" function in QLabel. + * Add some useful action when button is clicked, e.g. save document or show tool-tip + * or find a way to not show a "focus frame" when hovered by mouse + */ + m_modified = new StatusBarButton(this); + topLayout->addWidget(m_modified, 0); + /** * show Line XXX, Column XXX */ - m_lineColLabel = new QLabel(this); - m_lineColLabel->installEventFilter(this); // register for doubleclick - topLayout->addWidget(m_lineColLabel, 0); - m_lineColLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - m_lineColLabel->setFocusProxy(m_view); - m_lineColLabel->setWhatsThis(i18n("Current cursor position. Doubleclick to go to specific line.")); + m_cursorPosition = new StatusBarButton(this); + topLayout->addWidget(m_cursorPosition, 0); + m_cursorPosition->setWhatsThis(i18n("Current cursor position. Click to go to a specific line.")); + connect(m_cursorPosition, &StatusBarButton::clicked, m_view, &KTextEditor::ViewPrivate::gotoLine); /** * show word count @@ -96,15 +115,16 @@ m_wordCountLabel->setWhatsThis(i18n("Words and Chars count in document/selection.")); m_wordCountLabel->hide(); + // Separate the status line in a left and right part + topLayout->addStretch(1); + /** * show the current mode, like INSERT, OVERWRITE, VI + modifiers like [BLOCK] */ - m_insertModeLabel = new QLabel(this); - m_insertModeLabel->installEventFilter(this); // register for doubleclick - topLayout->addWidget(m_insertModeLabel, 1000 /* this one should stretch */); - m_insertModeLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); - m_insertModeLabel->setFocusProxy(m_view); - m_insertModeLabel->setWhatsThis(i18n("Insert mode and VI input mode indicator")); + m_inputMode = new StatusBarButton(this); + topLayout->addWidget(m_inputMode); + m_inputMode->setWhatsThis(i18n("Insert mode and VI input mode indicator. Click to change the mode.")); + connect(m_inputMode, &StatusBarButton::clicked, [=] { m_view->currentInputMode()->toggleInsert(); }); /** * allow to change indentation configuration @@ -118,10 +138,8 @@ m_tabGroup = new QActionGroup(this); m_indentGroup = new QActionGroup(this); - m_tabsIndent = new QPushButton(QString(), this); - m_tabsIndent->setFlat(true); + m_tabsIndent = new StatusBarButton(this); topLayout->addWidget(m_tabsIndent, 0); - m_tabsIndent->setFocusProxy(m_view); m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); m_indentSettingsMenu->addSection(i18n("Tab Width")); @@ -156,82 +174,59 @@ * add encoding button which allows user to switch encoding of document * this will reuse the encoding action menu of the view */ - m_encoding = new QPushButton(QString(), this); - m_encoding->setFlat(true); + m_encoding = new StatusBarButton(this); topLayout->addWidget(m_encoding, 0); m_encoding->setMenu(m_view->encodingAction()->menu()); - m_encoding->setFocusProxy(m_view); m_encoding->setWhatsThis(i18n("Encoding")); /** * add mode button which allows user to switch mode of document * this will reuse the mode action menu of the view */ - m_mode = new QPushButton(QString(), this); - m_mode->setFlat(true); + m_mode = new StatusBarButton(this); topLayout->addWidget(m_mode, 0); m_mode->setMenu(m_view->modeAction()->menu()); - m_mode->setFocusProxy(m_view); m_mode->setWhatsThis(i18n("Syntax highlighting")); - /** - * show modification state of the document - */ - m_modifiedLabel = new QToolButton(this); - m_modifiedLabel->setAutoRaise(true); - m_modifiedLabel->setEnabled(false); - topLayout->addWidget(m_modifiedLabel, 0); - m_modifiedLabel->setFocusProxy(m_view); - /** * add a bit space */ topLayout->addSpacing(4); // signals for the statusbar - connect(m_view, SIGNAL(cursorPositionChanged(KTextEditor::View*, KTextEditor::Cursor)), this, SLOT(cursorPositionChanged())); - connect(m_view, SIGNAL(viewModeChanged(KTextEditor::View*, KTextEditor::View::ViewMode)), this, SLOT(viewModeChanged())); - connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(selectionChanged())); - 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())); - connect(m_view->document(), SIGNAL(modeChanged(KTextEditor::Document*)), this, SLOT(modeChanged())); + connect(m_view, &KTextEditor::View::cursorPositionChanged, this, &KateStatusBar::cursorPositionChanged); + connect(m_view, &KTextEditor::View::viewModeChanged, this, &KateStatusBar::viewModeChanged); + connect(m_view, &KTextEditor::View::selectionChanged, this, &KateStatusBar::selectionChanged); + connect(m_view->document(), &KTextEditor::DocumentPrivate::modifiedChanged, this, &KateStatusBar::modifiedChanged); + connect(m_view->doc(), &KTextEditor::DocumentPrivate::modifiedOnDisk, this, &KateStatusBar::modifiedChanged); + connect(m_view->doc(), &KTextEditor::DocumentPrivate::configChanged, this, &KateStatusBar::documentConfigChanged); + connect(m_view->document(), &KTextEditor::DocumentPrivate::modeChanged, this, &KateStatusBar::modeChanged); connect(m_view, &KTextEditor::ViewPrivate::configChanged, this, &KateStatusBar::configChanged); - connect(m_tabGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotTabGroup(QAction*))); - connect(m_indentGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotIndentGroup(QAction*))); - connect(radioGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotIndentTabMode(QAction*))); + connect(m_tabGroup, &QActionGroup::triggered, this, &KateStatusBar::slotTabGroup); + connect(m_indentGroup, &QActionGroup::triggered, this, &KateStatusBar::slotIndentGroup); + connect(radioGroup, &QActionGroup::triggered, this, &KateStatusBar::slotIndentTabMode); updateStatus(); wordCountChanged(0, 0, 0, 0); } bool KateStatusBar::eventFilter(QObject *obj, QEvent *event) { - if (obj == m_insertModeLabel) { - if (event->type() == QEvent::MouseButtonDblClick) { - m_view->currentInputMode()->toggleInsert(); - return true; - } - } else if (obj == m_lineColLabel) { - if (event->type() == QEvent::MouseButtonDblClick) { - m_view->gotoLine(); - return true; - } - } - return KateViewBarWidget::eventFilter(obj, event); } void KateStatusBar::contextMenuEvent(QContextMenuEvent *event) { + // TODO Add option "Show Statusbar" and options to show/hide buttons of the status bar QMenu menu(this); QAction *showLines = menu.addAction(QStringLiteral("Show line count"), this, &KateStatusBar::toggleShowLines); showLines->setCheckable(true); showLines->setChecked(KateViewConfig::global()->showLineCount()); QAction *showWords = menu.addAction(QStringLiteral("Show word count"), this, &KateStatusBar::toggleShowWords); showWords->setCheckable(true); showWords->setChecked(KateViewConfig::global()->showWordCount()); menu.exec(event->globalPos()); + } void KateStatusBar::toggleShowLines(bool checked) @@ -273,24 +268,24 @@ if (m_view->blockSelection()) text = i18n("[BLOCK] %1", text); - m_insertModeLabel->setText(text); + m_inputMode->setText(text); } void KateStatusBar::cursorPositionChanged() { KTextEditor::Cursor position(m_view->cursorPositionVirtual()); if (KateViewConfig::global()->showLineCount()) - m_lineColLabel->setText( + m_cursorPosition->setText( i18n("Line %1 of %2, Column %3" , QLocale().toString(position.line() + 1) , QLocale().toString(m_view->doc()->lines()) , QLocale().toString(position.column() + 1) ) ); else - m_lineColLabel->setText( + m_cursorPosition->setText( i18n("Line %1, Column %2" , QLocale().toString(position.line() + 1) , QLocale().toString(position.column() + 1) @@ -313,24 +308,24 @@ m_modifiedStatus = newStatus; switch (m_modifiedStatus) { case 0x1: - m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("document-save"))); - m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was modified since it was loaded")); + m_modified->setIcon(QIcon::fromTheme(QStringLiteral("document-save"))); + m_modified->setWhatsThis(i18n("Meaning of current icon: Document was modified since it was loaded")); break; case 0x2: - m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); - m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was modified or deleted by another program")); + m_modified->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); + m_modified->setWhatsThis(i18n("Meaning of current icon: Document was modified or deleted by another program")); break; case 0x3: - m_modifiedLabel->setIcon(QIcon(KIconUtils::addOverlay(QIcon::fromTheme(QStringLiteral("document-save")), + m_modified->setIcon(QIcon(KIconUtils::addOverlay(QIcon::fromTheme(QStringLiteral("document-save")), QIcon(QStringLiteral("emblem-important")), Qt::TopLeftCorner))); - m_modifiedLabel->setWhatsThis(QString()); + m_modified->setWhatsThis(QString()); break; default: - m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("text-plain"))); - m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was not modified since it was loaded")); + m_modified->setIcon(QIcon::fromTheme(QStringLiteral("text-plain"))); + m_modified->setWhatsThis(i18n("Meaning of current icon: Document was not modified since it was loaded")); break; } }