mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Implemented supprt for customdock area title bar buttons
This commit is contained in:
parent
6a8b26f415
commit
094fa37135
@ -56,6 +56,7 @@
|
||||
#include <QScreen>
|
||||
#include <QStyle>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QAxWidget>
|
||||
@ -129,7 +130,7 @@ static void appendFeaturStringToWindowTitle(ads::CDockWidget* DockWidget)
|
||||
*/
|
||||
static QIcon svgIcon(const QString& File)
|
||||
{
|
||||
// This is a workaround, because because in item views SVG icons are not
|
||||
// This is a workaround, because in item views SVG icons are not
|
||||
// properly scaled an look blurry or pixelate
|
||||
QIcon SvgIcon(File);
|
||||
SvgIcon.addPixmap(SvgIcon.pixmap(92));
|
||||
@ -180,6 +181,18 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
|
||||
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
|
||||
DockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true);
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
|
||||
QMenu* OptionsMenu = new QMenu(DockWidget);
|
||||
OptionsMenu->setTitle(QObject::tr("Options"));
|
||||
OptionsMenu->setToolTip(OptionsMenu->title());
|
||||
OptionsMenu->setIcon(svgIcon(":/adsdemo/images/custom-menu-button.svg"));
|
||||
auto MenuAction = OptionsMenu->menuAction();
|
||||
// The object name of the action will be set for the QToolButton that
|
||||
// is created in the dock area title bar. You can use this name for CSS
|
||||
// styling
|
||||
MenuAction->setObjectName("optionsMenu");
|
||||
DockWidget->setTitleBarActions({OptionsMenu->menuAction()});
|
||||
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
@ -9,5 +9,6 @@
|
||||
<file>images/date_range.svg</file>
|
||||
<file>images/edit.svg</file>
|
||||
<file>images/grid_on.svg</file>
|
||||
<file>images/custom-menu-button.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
32
demo/images/custom-menu-button.svg
Normal file
32
demo/images/custom-menu-button.svg
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="16px" height="16px" viewBox="0 0 16 16" id="svg2" version="1.1" inkscape:version="0.91 r13725" sodipodi:docname="38 - menu bar lines option list hamburger web.svg">
|
||||
<defs id="defs4">
|
||||
<pattern y="0" x="0" height="6" width="6" patternUnits="userSpaceOnUse" id="EMFhbasepattern"/>
|
||||
<pattern y="0" x="0" height="6" width="6" patternUnits="userSpaceOnUse" id="EMFhbasepattern-4"/>
|
||||
<pattern y="0" x="0" height="6" width="6" patternUnits="userSpaceOnUse" id="EMFhbasepattern-3"/>
|
||||
<pattern y="0" x="0" height="6" width="6" patternUnits="userSpaceOnUse" id="EMFhbasepattern-8"/>
|
||||
</defs>
|
||||
<sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" inkscape:cx="6.2316889" inkscape:cy="7.4271635" inkscape:document-units="px" inkscape:current-layer="g5228" showgrid="true" units="px" inkscape:window-width="1366" inkscape:window-height="705" inkscape:window-x="-8" inkscape:window-y="-8" inkscape:window-maximized="1" inkscape:snap-bbox="true" inkscape:bbox-paths="true" inkscape:bbox-nodes="true" inkscape:snap-bbox-edge-midpoints="true" inkscape:snap-bbox-midpoints="true" inkscape:snap-global="true">
|
||||
<inkscape:grid type="xygrid" id="grid3336"/>
|
||||
</sodipodi:namedview>
|
||||
|
||||
<g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)">
|
||||
<g transform="translate(628,-140.49998)" id="g5228">
|
||||
<path style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" d="M 4.484375 4 A 0.50005 0.50005 0 0 0 4.5351562 5 L 11.464844 5 A 0.50005 0.50005 0 1 0 11.464844 4 L 4.5351562 4 A 0.50005 0.50005 0 0 0 4.484375 4 z M 4.484375 7 A 0.50005 0.50005 0 0 0 4.5351562 8 L 11.464844 8 A 0.50005 0.50005 0 1 0 11.464844 7 L 4.5351562 7 A 0.50005 0.50005 0 0 0 4.484375 7 z M 4.484375 10 A 0.50005 0.50005 0 0 0 4.5351562 11 L 11.464844 11 A 0.50005 0.50005 0 1 0 11.464844 10 L 4.5351562 10 A 0.50005 0.50005 0 0 0 4.484375 10 z " transform="translate(-628,1176.8622)" id="path3340"/>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
|
||||
|
||||
|
||||
<metadata>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<rdf:Description about="https://iconscout.com/legal#licenses" dc:title="Menu, Bar, Lines, Option, List, Hamburger, Web" dc:description="Menu, Bar, Lines, Option, List, Hamburger, Web" dc:publisher="Iconscout" dc:date="2016-12-14" dc:format="image/svg+xml" dc:language="en">
|
||||
<dc:creator>
|
||||
<rdf:Bag>
|
||||
<rdf:li>Jemis Mali</rdf:li>
|
||||
</rdf:Bag>
|
||||
</dc:creator>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</metadata></svg>
|
After Width: | Height: | Size: 3.9 KiB |
@ -576,7 +576,6 @@ void CDockAreaTabBar::closeTab(int Index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Tab->hide();
|
||||
emit tabCloseRequested(Index);
|
||||
}
|
||||
|
||||
@ -643,5 +642,6 @@ eDragState CDockAreaTabBar::dragState() const
|
||||
|
||||
} // namespace ads
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF DockAreaTabBar.cpp
|
||||
|
@ -70,6 +70,7 @@ struct DockAreaTitleBarPrivate
|
||||
CDockAreaTabBar* TabBar;
|
||||
bool MenuOutdated = true;
|
||||
QMenu* TabsMenu;
|
||||
QList<tTitleBarButton*> DockWidgetActionsButtons;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -188,7 +189,6 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||
|
||||
|
||||
// Undock button
|
||||
UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton));
|
||||
UndockButton->setObjectName("undockButton");
|
||||
@ -361,11 +361,39 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
||||
return;
|
||||
}
|
||||
|
||||
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
}
|
||||
|
||||
if (!d->DockWidgetActionsButtons.isEmpty())
|
||||
{
|
||||
for (auto Button : d->DockWidgetActionsButtons)
|
||||
{
|
||||
d->TopLayout->removeWidget(Button);
|
||||
delete Button;
|
||||
}
|
||||
d->DockWidgetActionsButtons.clear();
|
||||
}
|
||||
|
||||
auto Actions = DockWidget->titleBarActions();
|
||||
if (Actions.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int InsertIndex = 2;
|
||||
for (auto Action : Actions)
|
||||
{
|
||||
auto Button = new CTitleBarButton(true, this);
|
||||
Button->setDefaultAction(Action);
|
||||
Button->setAutoRaise(true);
|
||||
Button->setPopupMode(QToolButton::InstantPopup);
|
||||
Button->setObjectName(Action->objectName());
|
||||
d->TopLayout->insertWidget(InsertIndex++, Button, 0);
|
||||
d->DockWidgetActionsButtons.append(Button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,6 +80,7 @@ struct DockWidgetPrivate
|
||||
QSize ToolBarIconSizeDocked = QSize(16, 16);
|
||||
QSize ToolBarIconSizeFloating = QSize(24, 24);
|
||||
bool IsFloatingTopLevel = false;
|
||||
QList<QAction*> TitleBarActions;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -817,6 +818,20 @@ bool CDockWidget::closeDockWidgetInternal(bool ForceClose)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setTitleBarActions(QList<QAction*> actions)
|
||||
{
|
||||
d->TitleBarActions = actions;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QList<QAction*> CDockWidget::titleBarActions() const
|
||||
{
|
||||
return d->TitleBarActions;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -401,6 +401,22 @@ public:
|
||||
*/
|
||||
QSize toolBarIconSize(eState State) const;
|
||||
|
||||
/**
|
||||
* Set the actions that will be shown in the dock area title bar
|
||||
* if this dock widget is the active tab.
|
||||
* You should not add to many actions to the title bar, because this
|
||||
* will remove the available space for the tabs. If you have a number
|
||||
* of actions, just add an action with a menu to show a popup menu
|
||||
* button in the title bar.
|
||||
*/
|
||||
void setTitleBarActions(QList<QAction*> actions);
|
||||
|
||||
/**
|
||||
* Returns a list of actions that will be inserted into the dock area title
|
||||
* bar if this dock widget becomes the current widget
|
||||
*/
|
||||
virtual QList<QAction*> titleBarActions() const;
|
||||
|
||||
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user