Show icons in icon border context menu
ClosedPublic

Authored by croick on Aug 21 2017, 10:34 PM.

Details

Summary
  • if icons are defined for marks, use them in the context menu
  • more general approach than D7158
Test Plan
  • right click icon border to open context menu

Diff Detail

Repository
R39 KTextEditor
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
croick created this revision.Aug 21 2017, 10:34 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptAug 21 2017, 10:34 PM
Restricted Application added subscribers: Frameworks, kwrite-devel. · View Herald Transcript
kfunk added a subscriber: kfunk.Aug 22 2017, 6:44 AM

Other than that the patch looks sensible to me.

src/view/kateviewhelpers.cpp
2254

Less code with:

if (auto icon = ...) {
    mA->setIcon(icon);
    dMA->setIcon(icon);
}
dhaumann requested changes to this revision.Aug 22 2017, 7:13 PM
dhaumann added a subscriber: dhaumann.

I think we need one more iteration, then this is good to go, see the comments.

src/view/kateviewhelpers.cpp
2254

What most likely would work is this:

if (!m_doc->markDescription(markType).isEmpty()) {
    const QPixmap icon = m_doc->markPixmap(markType);
    mA = markMenu.addAction(icon, m_doc->markDescription(markType));
    dMA = selectDefaultMark.addAction(icon, m_doc->markDescription(markType));
} else {
    mA = markMenu.addAction(i18n("Mark Type %1",  bit + 1));
    dMA = selectDefaultMark.addAction(i18n("Mark Type %1",  bit + 1));
}

Looking at the Qt code of the constructor QIcon(const QPixmap & ) it becomes clear that a null pixmap will simply create a null icon. And a null QIcon will not be displayed in the gui, so we do not need the if at all, right?

Could you test this?

This revision now requires changes to proceed.Aug 22 2017, 7:13 PM
croick updated this revision to Diff 18554.Aug 22 2017, 7:42 PM
croick edited edge metadata.
  • use icon without checking
croick marked an inline comment as done.Aug 22 2017, 7:48 PM

Yes, the QAction simply overwrites its icon, which then just stays null. Works fine, thank you!

dhaumann accepted this revision.Aug 22 2017, 8:19 PM

Good patch, thanks a lot! You can make the QPixmap const, if you want: const QPixmap icon = ...;

Please commit.

This revision is now accepted and ready to land.Aug 22 2017, 8:19 PM
This revision was automatically updated to reflect the committed changes.