Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tearing off tags menu #11652

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,15 +820,15 @@ void MainWindow::updateSetTagsMenu()
if (dbWidget) {
// Enumerate tags applied to the selected entries
QSet<QString> selectedTags;
for (auto entry : dbWidget->entryView()->selectedEntries()) {
for (auto tag : entry->tagList()) {
for (const auto entry : dbWidget->entryView()->selectedEntries()) {
for (const auto& tag : entry->tagList()) {
selectedTags.insert(tag);
}
}

// Add known database tags as actions and set checked if
// a selected entry has that tag
for (auto tag : dbWidget->database()->tagList()) {
for (const auto& tag : dbWidget->database()->tagList()) {
auto action = m_ui->menuTags->addAction(icons()->icon("tag"), tag);
action->setCheckable(true);
action->setChecked(selectedTags.contains(tag));
Expand Down Expand Up @@ -938,6 +938,14 @@ void MainWindow::updateMenuActionState()
m_ui->menuEntryCopyAttribute->setEnabled(singleEntryOrEditing);
m_ui->menuEntryTotp->setEnabled(singleEntrySelected);
m_ui->menuTags->setEnabled(multiEntrySelected);
// Handle tear-off tags menu
if (m_ui->menuTags->isTearOffMenuVisible()) {
if (!databaseUnlocked) {
m_ui->menuTags->hideTearOffMenu();
} else {
updateSetTagsMenu();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove this line, everything works just fine. I think this function is already called via signal/slot in line 257?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is necessary to update the tags list when you change your entry selection choices. Saw no crashes on Windows so that's weird.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the problem, please re-test on your end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it, it works without errors

Copy link
Member

@varjolintu varjolintu Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still crashes for me. Sometimes the tearoff menu works, sometimes enabling it will crash directly, sometimes setting a tag crashes:

KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 properties: {
    IOSurfaceAllocSize = 0;
    IOSurfaceBytesPerElement = 4;
    IOSurfaceBytesPerRow = 0;
    IOSurfaceHeight = 0;
    IOSurfaceName = "libqcocoa.dylib";
    IOSurfacePixelFormat = 1111970369;
    IOSurfaceWidth = 0;
}
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceWidth
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceBytesPerElementKeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfacePixelFormat
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceBytesPerRow
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceHeight
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceAllocSize
KeePassXC[94447:7219921] IOSurface creation failed: e00002bd parentID: 00000000 property: IOSurfaceName
KeePassXC[94447:7219921] [qt.qpa.backingstore.iosurface] Failed to lock QIOSurfaceGraphicsBuffer(0x6000011e9c80, surface=0x0, size=QSize(0, 0), isLocked=false, isInUse=false) -536870206
Exception: EXC_BREAKPOINT (code=1, subcode=0x19c67cdcc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a major bug in qt5 macos when it comes to tear off menus.

}
}
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected && dbWidget->currentEntryHasAutoTypeEnabled());
m_ui->actionEntryAutoType->menu()->setEnabled(singleEntrySelected && dbWidget->currentEntryHasAutoTypeEnabled());
m_ui->actionEntryAutoTypeSequence->setText(singleEntrySelected
Expand Down
3 changes: 3 additions & 0 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@
<addaction name="actionEntrySetupTotp"/>
</widget>
<widget class="QMenu" name="menuTags">
<property name="tearOffEnabled">
<bool>true</bool>
</property>
<property name="title">
<string>Tags</string>
</property>
Expand Down
14 changes: 14 additions & 0 deletions src/gui/styles/base/BaseStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,21 @@ void BaseStyle::drawControl(ControlElement element,
}
break;
}
case CE_MenuTearoff: {
if (option->state & State_Selected) {
painter->fillRect(option->rect, option->palette.brush(QPalette::Highlight));
painter->setPen(QPen(option->palette.highlightedText().color(), 1, Qt::DashLine));
} else {
painter->fillRect(option->rect, option->palette.brush(QPalette::Button));
painter->setPen(QPen(option->palette.buttonText().color(), 1, Qt::DashLine));
}

painter->drawLine(option->rect.x() + 2,
option->rect.y() + option->rect.height() / 2,
option->rect.x() + option->rect.width() - 4,
option->rect.y() + option->rect.height() / 2);
break;
}
case CE_MenuItem: {
auto menuItem = qstyleoption_cast<const QStyleOptionMenuItem*>(option);
if (!menuItem)
Expand Down
Loading