Compare commits

...

73 Commits
3.0.0 ... 3.2.5

Author SHA1 Message Date
Uwe Kindler
661d0c4356 Removed dead code in comment of DockAreaWidget 2020-03-25 14:38:10 +01:00
Uwe Kindler
dceaa155c4 Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-03-25 14:35:26 +01:00
Uwe Kindler
c541f2c69b DockWidget now also emits closed() signal if DockWidgetDeleteOnClose flag is set 2020-03-25 14:34:42 +01:00
Uwe Kindler
37d305e50d Fixed documentation of toolBarIconSize() function of DockWidget 2020-03-25 14:23:27 +01:00
K Lauer
4adef2b774 FIX: DockContainerWidget::dropWidget API change not reflected in Python bindings (#133)
* FIX: dropWidget API change not reflected in Python bindings

* Add missing methods to Python bindings (3.2.4)
2020-03-17 09:12:00 +01:00
Uwe Kindler
1c2383f8eb Fixed regression #132 - Inner drop areas don't work with multi tab DockWidgets 2020-03-12 20:29:03 +01:00
Uwe Kindler
6c687d28de Fixxed isse #131 - Crash on dropping in same area multiple times 2020-03-12 10:23:41 +01:00
Uwe Kindler
708add3ff5 Fixed two linter warnings in CDockManager 2020-03-12 08:01:57 +01:00
Uwe Kindler
e85b4167bd Changed CDockManager::addToggleViewActionToMenu to support later setting of group icon 2020-03-10 09:11:36 +01:00
Uwe Kindler
59c783831a Fixed wrong test for VisibleDockAreas 2020-03-07 16:18:19 +01:00
Uwe Kindler
4cb1931ace Fixed display of container dock overlay if only one single visible dock area is in a container 2020-03-02 11:21:44 +01:00
Uwe Kindler
fe10b570d3 Fixed reception of escape key press events 2020-02-26 20:51:29 +01:00
Uwe Kindler
f3c5d51380 Improved documentation for setting dock manager flags 2020-02-26 13:25:17 +01:00
Uwe Kindler
34cb2ae917 Fixed escape key press detection 2020-02-25 09:16:21 +01:00
Hugo Slepicka
8cc9cc25ad Fixed and updated Python integration (#127)
* FIX: Add Q_OS_MACOS flag to moc compiler.

* (Python) Demo and example from @n-elie.

* FIX: Addressing some sip files that were inconsistent with the header files.

* (Python) Addressing comments by @n-elie and switching to use WS_X11 for platform checks.

* (Python) Wrap definition of tFloatingWidgetBase to avoid 'Already Defined' error and fix include path for sip/linux/FloatingWidgetTitleBar.sip.

* Remove simple.py

* Fix case sensitive ui file loading in Linux

* Add windows case in get_moc_args

* Remove conda recipe

Co-authored-by: n-elie <40382614+n-elie@users.noreply.github.com>
2020-02-25 07:22:51 +01:00
Hugo Slepicka
c90fb9413c FIX: Update Python SIP bindings 3.2.1 & Linux Crash (#126)
* (Python) WIP: attempt to update to 3.2.0

* (Python) MAINT: move demo.py to demo/ to avoid PyQtAds import issue

* (Python) STY: remove trailing whitespace

* (Python) Missing/incorrect /Transfer/ annotations

* (Python) n-elie's fix for setup.py moc generation

* (Python) FIX: Q_OS_LINUX is not defined by default with moc

* (Python) FIX: split FloatingDockContainer.sip to be platform-specific

%If (Platform) blocks around the class definition in
FloatingDockContainer.sip did not seem to work.

Co-authored-by: K Lauer <klauer@users.noreply.github.com>
2020-02-21 22:47:09 +01:00
Rodrigo Oliva
dec170ed24 Don't select a new tab if the tab being closed is not the current tab. (#125) 2020-02-21 22:46:21 +01:00
Uwe Kindler
3ffbbfb6d0 Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-02-19 22:51:53 +01:00
Uwe Kindler
e8332575f8 Improved tab dragging, added support for undocking if mouse leaves tabbar during tb dragging 2020-02-19 22:48:17 +01:00
Uwe Kindler
8c12d912b4 Improved tab dragging, added support for undocking if mouse leaves tabbar during tb dragging 2020-02-19 22:29:29 +01:00
Uwe Kindler
fd28f0f751 Update DockAreaTab bar to undock / shwo undock preview as soon as a tab is dragged outside of the tab bar 2020-02-19 22:07:17 +01:00
Uwe Kindler
3f09d5c6ea Fixed initial position for CFloatingDockContainer when dragging a tab outside of the tabbar 2020-02-19 18:36:57 +01:00
Uwe Kindler
3407945f19 Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-02-17 10:42:02 +01:00
Uwe Kindler
ce01e6b4a6 Fixed QT_VESION typo in DockOverlay.cpp 2020-02-17 10:41:13 +01:00
Sanakan8472
3428a4b8b4 Added CDockManager::floatingWidgetCreated event (#121)
This allows to subscribe to events of the newly created window.
A common use case is to show a message box if a dock container with many modified documents in it is closed. This allows for the user to decide whether he wants to save / discard all the changes or cancel the closing of the window.
2020-02-17 08:15:11 +01:00
Uwe Kindler
2b9377b5ee Fixed drag canceling via ESC key 2020-02-17 08:08:25 +01:00
Uwe Kindler
d4a18003d9 Properly implemented handling of DockWidget flag DockWidgetIsMovable for NonOpaque undocking - creating the drag preview is allowed even if the DockWidget is not floatable 2020-02-16 14:37:14 +01:00
Uwe Kindler
2c15d5dacd Fixed regression caused by setDockArea() function removed from DockWidgetTab 2020-02-14 22:56:48 +01:00
Uwe Kindler
f236de3277 Replaced all dynamic_casts with qobject_casts 2020-02-13 18:56:04 +01:00
Uwe Kindler
93394577d0 Merge branch 'master' into custom_titlebar 2020-02-13 13:53:56 +01:00
Uwe Kindler
f387c6aebc Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-02-13 13:51:11 +01:00
Uwe Kindler
41173d067b Switched QScopedPointer to std::unique_ptr in DockComponentsFactory 2020-02-13 13:45:40 +01:00
Uwe Kindler
5b60e39ed3 Removed unneeded functions 2020-02-13 13:04:08 +01:00
Uwe Kindler
1916bd726d Fixed build issue for older Qt versions 2020-02-11 15:46:19 +01:00
Uwe Kindler
3efc5f2ada Added DockComponentsFactory.h documentation, changed DockComponentsFactory showcase in MainWindow after discussion on GitHub 2020-02-11 15:38:49 +01:00
Uwe Kindler
3eba02597c Added missing svg icon 2020-02-11 11:57:53 +01:00
Uwe Kindler
65eeffd5e1 Added showcase for DockComponentsFactory - a help button is injected into a title bar 2020-02-11 09:31:57 +01:00
Uwe Kindler
ff1439c719 Added CDockComponentsFactory for creation of components for the docking framework 2020-02-11 08:32:49 +01:00
mvidelgauz
7ba20f37b7 Icon of floating window (#116)
* FloatingContainerHasWidgetTitle and FloatingContainerHasWidgetIcon config flags
2020-02-10 20:07:36 +01:00
Rodrigo Oliva
a4ef161f4f Fix using escape button when dragging non-opaque preview to cancel drag operation (#114)
* Added missing overrides.

* Escape button to cancel dragging was not working in Windows either. Using the event filter added for Linux works.
2020-02-07 23:07:07 +01:00
Uwe Kindler
8a16230213 Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-02-07 22:54:02 +01:00
Uwe Kindler
8113bf63ba Added spacer widget to handle mouse events properly in CDockAreaTitleBar, added missing updateGeometry calls to CDockAreaTabBar 2020-02-07 22:49:10 +01:00
Rodrigo Oliva
2770837adc Added missing overrides. (#113) 2020-02-07 14:41:35 +01:00
Uwe Kindler
c4872c6b10 Added showcase for custom title bar widget to demo application 2020-02-07 14:29:02 +01:00
Uwe Kindler
efb9b879dd Added functions to insert custom dock area title bar widgets 2020-02-07 13:42:11 +01:00
Uwe Kindler
d10d59a8e2 Porperly moved title bar context menu code from DockAreaTabBar into DockAreaTitleBar 2020-02-07 12:23:26 +01:00
Uwe Kindler
b61f50982a Moved title bar dragging code from DockAreaTabBar into DockAreaTitleBar 2020-02-07 12:16:26 +01:00
Uwe Kindler
ae72f5e47d Changed sizeHints(), sizePolicy() and used updateGeometry() to properly size the tabBar 2020-02-07 11:49:45 +01:00
Uwe Kindler
9d7c692398 Fixed stylesheet typo 2020-02-06 15:37:50 +01:00
mvidelgauz
474dd13855 Disable tabs menu button when only single tab exists in a Dock area (#111) 2020-02-06 15:21:19 +01:00
Uwe Kindler
72496ebd48 Comitted missing app.css file 2020-02-06 12:55:26 +01:00
Uwe Kindler
b727274cd9 Implemented support for custom DockWidget actions for display in DockArea title bar 2020-02-06 09:15:13 +01:00
Uwe Kindler
094fa37135 Implemented supprt for customdock area title bar buttons 2020-02-06 00:31:57 +01:00
Uwe Kindler
6a8b26f415 Added function internal::setButtonIcon to unify code for setting DockAreaTitleBar and DockWidgetTab icons 2020-02-05 08:57:57 +01:00
Uwe Kindler
acb423872a Helper function internal::setToolTip() to remove as many #ifndef QT_NO_TOOLTIP tests as possible to cleanup the code 2020-02-05 08:33:40 +01:00
Uwe Kindler
505f14a601 Improved code for generation of default configuration flags 2020-02-05 08:16:07 +01:00
Uwe Kindler
05c58a4ca9 Merge branch 'master' of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System 2020-02-05 08:05:10 +01:00
mvidelgauz
b8ed70fa33 Added DockAreaHideDisabledButtons configuration flag (#110)
* CInvisibleButton generalized to CTitleBarButton to serve more purposes
* Disabled buttons are hidden if CDockManager::DockAreaHideDisabledButtons set to true
2020-02-05 08:04:27 +01:00
Uwe Kindler
b510686fe2 Added icon to ads_qt_marketplace_manifest.json 2020-02-04 11:29:18 +01:00
Uwe Kindler
50652b05b0 Fixed svg icon 2020-02-04 10:07:20 +01:00
Uwe Kindler
66795f2b12 Changes in donate section 2020-02-04 09:36:41 +01:00
Uwe Kindler
bc5e0ba7d8 Fixed some README.md markdown issues and added donate button 2020-02-04 09:32:15 +01:00
Uwe Kindler
d722482913 Added library icon 2020-02-04 08:49:34 +01:00
mvidelgauz
1d68e27558 Added DockAreaHasTabsMenuButton and DockAreaHasUndockButton to CDockManager config (#108)
* Added DockAreaHasUndockButton and DockAreaHasTabsMenuButton configuration flag
2020-02-02 16:22:05 +01:00
Uwe Kindler
1dbd3f3f06 Blocked tabyfing via moving over DockArea titlebar if the CenterDockWidgetArea is not in the allowed areas for DockAreaWidget 2020-02-02 16:03:58 +01:00
Uwe Kindler
68b0958119 Removed unused code 2020-02-02 16:02:12 +01:00
mvidelgauz
6c3f82547d setAllowedAreas for individual DockAreaWidget (#107)
* setAllowedAreas for individual DockAreaWidget

* alligning tab policy with master
2020-02-02 15:56:31 +01:00
Uwe Kindler
9fe8f291fb Fixed CDockManager::DockAreaHasCloseButton == false issue 2020-02-02 11:16:38 +01:00
githubuser0xFFFF
102e65a548 Update CMakeLists.txt 2020-01-31 21:39:10 +01:00
Uwe Kindler
4f62794946 Added documentation for new AlwaysShowTabs flag 2020-01-31 14:36:05 +01:00
Rodrigo Oliva
dd06d84206 Add option to always show all tabs (#102)
* Add option to always show tabs.

* Disable "Detach" context menu option in tab if there is only one tab in the floating container.
2020-01-31 14:27:01 +01:00
Krzysztof Machura
d4c179c48e Fix tabs not being active when restoring state (#101)
Regression introduced by 29ebc83b35
2020-01-31 14:26:02 +01:00
Uwe Kindler
ff68ad95a6 Updated LICENSE file for better GitHub integration 2020-01-31 13:40:39 +01:00
70 changed files with 2977 additions and 1062 deletions

View File

@@ -42,6 +42,7 @@ set(ads_SRCS
src/FloatingDockContainer.cpp
src/FloatingDragPreview.cpp
src/IconProvider.cpp
src/DockComponentsFactory.cpp
src/ads.qrc
src/linux/FloatingWidgetTitleBar.cpp
)
@@ -61,6 +62,7 @@ set(ads_INSTALL_INCLUDE
src/FloatingDockContainer.h
src/FloatingDragPreview.h
src/IconProvider.h
src/DockComponentsFactory.h
src/linux/FloatingWidgetTitleBar.h
)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
@@ -80,7 +82,7 @@ install(FILES ${ads_INSTALL_INCLUDE}
COMPONENT headers
)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md"
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
"${CMAKE_CURRENT_SOURCE_DIR}/gnu-lgpl-v2.1.md"
DESTINATION license
COMPONENT license

504
LICENSE Normal file
View File

@@ -0,0 +1,504 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random
Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@@ -1,15 +0,0 @@
Qt Advanced Docking System
Copyright (C) 2017 Uwe Kindler
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; If not, see <http://www.gnu.org/licenses/>.

View File

@@ -1,4 +1,5 @@
# Advanced Docking System for Qt
# Advanced Docking System for Qt
[![Build Status](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System.svg?branch=master)](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System)
[![Build status](https://ci.appveyor.com/api/projects/status/qcfb3cy932jw9mpy/branch/master?svg=true)](https://ci.appveyor.com/project/githubuser0xFFFF/qt-advanced-docking-system/branch/master)
[![License: LGPL v2.1](https://img.shields.io/badge/License-LGPL%20v2.1-blue.svg)](gnu-lgpl-v2.1.md)
@@ -20,18 +21,36 @@ code quality, readibility and to fix all issues from the issue tracker
of his docking system project.
## Features
### Overview
- [Docking everywhere - no central widget](#docking-everywhere---no-central-widget)
- [Docking inside floating windows](#docking-inside-floating-windows)
- [Grouped dragging](#grouped-dragging)
- [Perspectives for fast switching of the complete main window layout](#perspectives-for-fast-switching-of-the-complete-main-window-layout)
- [Opaque and non-opaque splitter resizing](#opaque-and-non-opaque-splitter-resizing)
- [Opaque and non-opaque undocking](#opaque-and-non-opaque-undocking)
- [Tab-menu for easy handling of many tabbed dock widgets](#tab-menu-for-easy-handling-of-many-tabbed-dock-widgets)
- [Many different ways to detach dock widgets](#many-different-ways-to-detach-dock-widgets)
- [Supports deletion of dynamically created dock widgets](#supports-deletion-of-dynamically-created-dock-widgets)
- [Advanced Docking System for Qt](#advanced-docking-system-for-qt)
- [Features](#features)
- [Overview](#overview)
- [Docking everywhere - no central widget](#docking-everywhere---no-central-widget)
- [Docking inside floating windows](#docking-inside-floating-windows)
- [Grouped dragging](#grouped-dragging)
- [Perspectives for fast switching of the complete main window layout](#perspectives-for-fast-switching-of-the-complete-main-window-layout)
- [Opaque and non-opaque splitter resizing](#opaque-and-non-opaque-splitter-resizing)
- [Opaque and non-opaque undocking](#opaque-and-non-opaque-undocking)
- [Tab-menu for easy handling of many tabbed dock widgets](#tab-menu-for-easy-handling-of-many-tabbed-dock-widgets)
- [Many different ways to detach dock widgets](#many-different-ways-to-detach-dock-widgets)
- [Supports deletion of dynamically created dock widgets](#supports-deletion-of-dynamically-created-dock-widgets)
- [Tested Compatible Environments](#tested-compatible-environments)
- [Windows](#windows)
- [macOS](#macos)
- [Linux](#linux)
- [Build](#build)
- [Getting started / Example](#getting-started--example)
- [Developers](#developers)
- [License information](#license-information)
- [Alternative Docking System Implementations](#alternative-docking-system-implementations)
- [KDDockWidgets](#kddockwidgets)
- [QtitanDocking](#qtitandocking)
- [Donation](#donation)
### Docking everywhere - no central widget
There is no central widget like in the Qt docking system. You can dock on every
border of the main window or you can dock into each dock area - so you are
free to dock almost everywhere.
@@ -41,6 +60,7 @@ free to dock almost everywhere.
![Dropping widgets](doc/preview-dragndrop_dark.png)
### Docking inside floating windows
There is no difference between the main window and a floating window. Docking
into floating windows is supported.
@@ -49,6 +69,7 @@ into floating windows is supported.
![Docking inside floating windows](doc/floating-widget-dragndrop_dark.png)
### Grouped dragging
When dragging the titlebar of a dock, all the tabs that are tabbed with it are
going to be dragged. So you can move complete groups of tabbed widgets into
a floating widget or from one dock area to another one.
@@ -58,6 +79,7 @@ a floating widget or from one dock area to another one.
![Grouped dragging](doc/grouped-dragging_dark.png)
### Perspectives for fast switching of the complete main window layout
A perspective defines the set and layout of dock windows in the main
window. You can save the current layout of the dockmanager into a named
perspective to make your own custom perspective. Later you can simply
@@ -69,6 +91,7 @@ main window layout.
![Perspective](doc/perspectives_dark.png)
### Opaque and non-opaque splitter resizing
The advanced docking system uses standard QSplitters as resize separators and thus supports opaque and non-opaque resizing functionality of QSplitter. In some rare cases, for very complex widgets or on slow machines resizing via separator on the fly may cause flicking and glaring of rendered content inside a widget. The global dock manager flag `OpaqueSplitterResize` configures the resizing behaviour of the splitters. If this flag is set, then widgets are resized dynamically (opaquely) while interactively moving the splitters.
![Opaque resizing](doc/opaque_resizing.gif)
@@ -78,6 +101,7 @@ If this flag is cleared, the widget resizing is deferred until the mouse button
![Non-opaque resizing](doc/non_opaque_resizing.gif)
### Opaque and non-opaque undocking
By default, opaque undocking is active. That means, as soon as you drag a dock widget or a dock area with a number of dock widgets it will be undocked and moved into a floating widget and then the floating widget will be dragged around. That means undocking will take place immediatelly. You can compare this with opaque splitter resizing. If the flag `OpaqueUndocking` is cleared, then non-opaque undocking is active. In this mode, undocking is more like a standard drag and drop operation. That means, the dragged dock widget or dock area is not undocked immediatelly. Instead, a drag preview widget is created and dragged around to indicate the future position of the dock widget or dock area. The actual dock operation is only executed when the mouse button is released. That makes it possible, to cancel an active drag operation with the escape key.
The drag preview widget can be configured by a number of global dock manager flags:
@@ -88,26 +112,33 @@ The drag preview widget can be configured by a number of global dock manager fla
The best way to test non-opaque undocking is to set the standard flags: `CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig)`.
### Tab-menu for easy handling of many tabbed dock widgets
Tabs are a good way to quickly switch between dockwidgets in a dockarea. However, if the number of dockwidgets in a dockarea is too large, this may affect the usability of the tab bar. To keep track in this situation, you can use the tab menu. The menu allows you to quickly select the dockwidget you want to activate from a drop down menu.
![Tab menu](doc/tab_menu.gif)
### Many different ways to detach dock widgets
You can detach dock widgets and also dock areas in the following ways:
- by dragging the dock widget tab or the dock area title bar
- by double clicking the tab or title bar
- by using the detach menu entry from the tab and title bar drop down menu
### Supports deletion of dynamically created dock widgets
Normally clicking the close button of a dock widget will just hide the widget and the user can show it again using the toggleView() action of the dock widget. This is meant for user interfaces with a static amount of widgets. But the advanced docking system also supports dynamic dock widgets that will get deleted on close. If you set the dock widget flag `DockWidgetDeleteOnClose` for a certain dock widget, then it will be deleted as soon as you close this dock widget. This enables the implementation of user interfaces with dynamically created editors, like in word processing applications or source code development tools.
## Tested Compatible Environments
### Windows
Windows 10 [![Build status](https://ci.appveyor.com/api/projects/status/qcfb3cy932jw9mpy/branch/master?svg=true)](https://ci.appveyor.com/project/githubuser0xFFFF/qt-advanced-docking-system/branch/master)
The library was developed on and for Windows. It is used in a commercial Windows application and is therefore constantly tested.
### macOS
macOS [![Build Status](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System.svg?branch=master)](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System)
The application can be compiled for macOS. A user reported, that the library works on macOS. If have not tested it.
@@ -115,6 +146,7 @@ The application can be compiled for macOS. A user reported, that the library wor
![Advanced Docking on macOS](doc/macos.png)
### Linux
Ubuntu [![Build Status](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System.svg?branch=master)](https://travis-ci.org/githubuser0xFFFF/Qt-Advanced-Docking-System)
[![Build status](https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/workflows/linux-builds/badge.svg)](https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/actions?query=workflow%3Alinux-builds)
@@ -127,10 +159,12 @@ and with **Ubuntu 19.10**
![Advanced Docking on Ubuntu Linux](doc/linux_ubuntu_1910.png)
## Build
Open the `ads.pro` with QtCreator and start the build, that's it.
You can run the demo project and test it yourself.
## Getting started / Example
The following example shows the minimum code required to use the advanced Qt docking system.
*MainWindow.h*
@@ -158,7 +192,9 @@ private:
ads::CDockManager* m_DockManager;
};
```
*MainWindow.cpp*
```cpp
#include "MainWindow.h"
#include "ui_MainWindow.h"
@@ -202,17 +238,22 @@ MainWindow::~MainWindow()
```
## Developers
- Uwe Kindler, Project Maintainer
- Manuel Freiholz
## License information
[![License: LGPL v2.1](https://img.shields.io/badge/License-LGPL%20v2.1-blue.svg)](gnu-lgpl-v2.1.md)
This project uses the [LGPLv2.1 license](gnu-lgpl-v2.1.md)
## Alternative Docking System Implementations
If this Qt Advanced Docking System does not fit to your needs you may consider some of the alternative docking system solutions for Qt.
### KDDockWidgets
This is an advanced docking framework for Qt from [KDAB](https://www.kdab.com/). The interesting thing is, that they separated GUI code from logic, so they can easily provide a QtQuick backend in the future.
- [Blog post about KDDockWidgets](https://www.kdab.com/kddockwidgets/)
@@ -220,6 +261,15 @@ This is an advanced docking framework for Qt from [KDAB](https://www.kdab.com/).
### QtitanDocking
This is a commercial component from [Developer Machines](https://www.devmachines.com/) for Qt Framework that allows to create a Microsoft like dockable user interface. They also offer a lot of other interesting and useful components for Qt.
- [Product page](https://www.devmachines.com/qtitandocking-overview.html)
## Donation
If this project help you reduce time to develop or if you just like it, you can give me a cup of coffee :coffee::wink:.
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=85R64TMMSY9T6">
<img src="doc/donate.png" alt="Donate with PayPal" width="160"/>
</a>

316
demo.py
View File

@@ -1,316 +0,0 @@
import datetime
import logging
from PyQt5.QtCore import (QCoreApplication, QDir, Qt, QSettings, QSignalBlocker,
QRect)
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtWidgets import (QCalendarWidget, QFileSystemModel, QFrame, QLabel,
QMenu, QTreeView, QAction, QWidgetAction,
QComboBox, QStyle, QSizePolicy, QInputDialog)
from PyQt5 import QtWidgets
from PyQtAds import QtAds
class _State:
label_count = 0
calendar_count = 0
file_system_count = 0
def create_long_text_label_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
'''
Create long text label dock widget
Parameters
----------
view_menu : QMenu
Returns
-------
value : QtAds.CDockWidget
'''
label = QLabel()
label.setWordWrap(True)
label.setAlignment(Qt.AlignTop | Qt.AlignLeft)
label.setText('''\
Label {} {} - Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum
sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla
vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut,
imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis
pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.
Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu,
consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra
quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
'''.format(_State.label_count, str(datetime.datetime.now())))
_State.label_count += 1
dock_widget = QtAds.CDockWidget("Label {}".format(_State.label_count))
dock_widget.setWidget(label)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
def create_calendar_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
'''
Create calendar dock widget
Parameters
----------
view_menu : QMenu
Returns
-------
value : QtAds.CDockWidget
'''
widget = QCalendarWidget()
dock_widget = QtAds.CDockWidget("Calendar {}".format(_State.calendar_count))
_State.calendar_count += 1
dock_widget.setWidget(widget)
dock_widget.setToggleViewActionMode(QtAds.CDockWidget.ActionModeShow)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
def create_file_system_tree_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
'''
Create file system tree dock widget
Parameters
----------
view_menu : QMenu
Returns
-------
value : QtAds.CDockWidget
'''
widget = QTreeView()
widget.setFrameShape(QFrame.NoFrame)
m = QFileSystemModel(widget)
m.setRootPath(QDir.currentPath())
widget.setModel(m)
dock_widget = QtAds.CDockWidget("Filesystem {}".format(_State.file_system_count))
_State.file_system_count += 1
dock_widget.setWidget(widget)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
class MainWindow(QtWidgets.QMainWindow):
save_perspective_action: QAction
perspective_list_action: QWidgetAction
perspective_combo_box: QComboBox
dock_manager: QtAds.CDockManager
def __init__(self, parent=None):
super().__init__(parent)
self.save_perspective_action = None
self.perspective_list_action = None
self.perspective_combo_box = None
self.dock_manager = None
self.setup_ui()
self.dock_manager = QtAds.CDockManager(self)
self.perspective_combo_box.activated[str].connect(self.dock_manager.openPerspective)
self.create_content()
self.resize(800, 600)
self.restore_state()
self.restore_perspectives()
def setup_ui(self):
self.setObjectName("MainWindow")
self.resize(400, 300)
self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks)
self.centralWidget = QtWidgets.QWidget(self)
self.centralWidget.setObjectName("centralWidget")
self.setCentralWidget(self.centralWidget)
self.status_bar = QtWidgets.QStatusBar(self)
self.status_bar.setObjectName("statusBar")
self.setStatusBar(self.status_bar)
self.menu_bar = QtWidgets.QMenuBar(self)
self.menu_bar.setGeometry(QRect(0, 0, 400, 21))
self.menu_bar.setObjectName("menuBar")
self.menu_file = QtWidgets.QMenu(self.menu_bar)
self.menu_file.setObjectName("menuFile")
self.menu_view = QtWidgets.QMenu(self.menu_bar)
self.menu_view.setObjectName("menuView")
self.menu_about = QtWidgets.QMenu(self.menu_bar)
self.menu_about.setObjectName("menuAbout")
self.setMenuBar(self.menu_bar)
self.tool_bar = QtWidgets.QToolBar(self)
self.tool_bar.setObjectName("toolBar")
self.addToolBar(Qt.TopToolBarArea, self.tool_bar)
self.action_exit = QtWidgets.QAction(self)
self.action_exit.setObjectName("actionExit")
self.action_save_state = QtWidgets.QAction(self)
self.action_save_state.setObjectName("actionSaveState")
self.action_save_state.triggered.connect(self.saveState)
self.action_restore_state = QtWidgets.QAction(self)
self.action_restore_state.setObjectName("actionRestoreState")
self.action_restore_state.triggered.connect(self.restore_state)
self.menu_file.addAction(self.action_exit)
self.menu_file.addAction(self.action_save_state)
self.menu_file.addAction(self.action_restore_state)
self.menu_bar.addAction(self.menu_file.menuAction())
self.menu_bar.addAction(self.menu_view.menuAction())
self.menu_bar.addAction(self.menu_about.menuAction())
self.setWindowTitle("MainWindow")
self.menu_file.setTitle("File")
self.menu_view.setTitle("View")
self.menu_about.setTitle("About")
self.tool_bar.setWindowTitle("toolBar")
self.action_exit.setText("Exit")
self.action_save_state.setText("Save State")
self.action_restore_state.setText("Restore State")
self.create_actions()
def create_actions(self):
'''
Creates the toolbar actions
'''
self.tool_bar.addAction(self.action_save_state)
self.action_save_state.setIcon(self.style().standardIcon(QStyle.SP_DialogSaveButton))
self.tool_bar.addAction(self.action_restore_state)
self.action_restore_state.setIcon(self.style().standardIcon(QStyle.SP_DialogOpenButton))
self.save_perspective_action = QAction("Save Perspective", self)
self.save_perspective_action.triggered.connect(self.save_perspective)
self.perspective_list_action = QWidgetAction(self)
self.perspective_combo_box = QComboBox(self)
self.perspective_combo_box.setSizeAdjustPolicy(QComboBox.AdjustToContents)
self.perspective_combo_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.perspective_list_action.setDefaultWidget(self.perspective_combo_box)
self.tool_bar.addSeparator()
self.tool_bar.addAction(self.perspective_list_action)
self.tool_bar.addAction(self.save_perspective_action)
def create_content(self):
'''
Fill the dock manager with dock widgets
'''
# Test container docking
view_menu = self.menu_view
dock_widget = create_calendar_dock_widget(view_menu)
dock_widget.setIcon(self.style().standardIcon(QStyle.SP_DialogOpenButton))
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetClosable, False)
self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, dock_widget)
self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, create_long_text_label_dock_widget(view_menu))
file_system_widget = create_file_system_tree_dock_widget(view_menu)
tool_bar = file_system_widget.createDefaultToolBar()
tool_bar.addAction(self.action_save_state)
tool_bar.addAction(self.action_restore_state)
self.dock_manager.addDockWidget(QtAds.BottomDockWidgetArea, file_system_widget)
file_system_widget = create_file_system_tree_dock_widget(view_menu)
tool_bar = file_system_widget.createDefaultToolBar()
tool_bar.addAction(self.action_save_state)
tool_bar.addAction(self.action_restore_state)
file_system_widget.setFeature(QtAds.CDockWidget.DockWidgetMovable, False)
top_dock_area = self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, file_system_widget)
dock_widget = create_calendar_dock_widget(view_menu)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetClosable, False)
dock_widget.setTabToolTip("Tab ToolTip\nHodie est dies magna")
self.dock_manager.addDockWidget(QtAds.CenterDockWidgetArea, dock_widget, top_dock_area)
# Test dock area docking
right_dock_area = self.dock_manager.addDockWidget(
QtAds.RightDockWidgetArea,
create_long_text_label_dock_widget(view_menu), top_dock_area)
self.dock_manager.addDockWidget(
QtAds.TopDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
bottom_dock_area = self.dock_manager.addDockWidget(
QtAds.BottomDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
self.dock_manager.addDockWidget(
QtAds.RightDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
self.dock_manager.addDockWidget(
QtAds.CenterDockWidgetArea,
create_long_text_label_dock_widget(view_menu), bottom_dock_area)
def save_state(self):
'''
Saves the dock manager state and the main window geometry
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
settings.setValue("mainWindow/Geometry", self.saveGeometry())
settings.setValue("mainWindow/State", self.saveState())
settings.setValue("mainWindow/DockingState", self.dock_manager.saveState())
def save_perspectives(self):
'''
Save the list of perspectives
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
self.dock_manager.savePerspectives(settings)
def restore_state(self):
'''
Restores the dock manager state
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
geom = settings.value("mainWindow/Geometry")
if geom is not None:
self.restoreGeometry(geom)
state = settings.value("mainWindow/State")
if state is not None:
self.restoreState(state)
state = settings.value("mainWindow/DockingState")
if state is not None:
self.dock_manager.restore_state(state)
def restore_perspectives(self):
'''
Restore the perspective listo of the dock manager
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
self.dock_manager.loadPerspectives(settings)
self.perspective_combo_box.clear()
self.perspective_combo_box.addItems(self.dock_manager.perspectiveNames())
def save_perspective(self):
perspective_name, ok = QInputDialog.getText(self, 'Save perspective', 'Enter unique name:')
if ok and perspective_name:
self.dock_manager.addPerspective(perspective_name)
_ = QSignalBlocker(self.perspective_combo_box)
self.perspective_combo_box.clear()
self.perspective_combo_box.addItems(self.dock_manager.perspectiveNames())
self.perspective_combo_box.setCurrentText(perspective_name)
self.save_perspectives()
def main(app_):
main_window = MainWindow()
main_window.show()
state = main_window.dock_manager.saveState()
# print('This is what the saved state looks like in XML:')
# print(str(state, 'utf-8'))
# print()
# main_window.dock_manager.restore_state(state)
return main_window
if __name__ == '__main__':
# logging.basicConfig(level='DEBUG')
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication([])
window = main(app)
window.show()
app.exec_()

View File

@@ -56,6 +56,9 @@
#include <QScreen>
#include <QStyle>
#include <QMessageBox>
#include <QMenu>
#include <QToolButton>
#ifdef Q_OS_WIN
#include <QAxWidget>
@@ -67,7 +70,11 @@
#include "DockManager.h"
#include "DockWidget.h"
#include "DockAreaWidget.h"
#include "DockAreaTitleBar.h"
#include "DockAreaTabBar.h"
#include "FloatingDockContainer.h"
#include "DockComponentsFactory.h"
//============================================================================
@@ -129,7 +136,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));
@@ -137,6 +144,25 @@ static QIcon svgIcon(const QString& File)
}
//============================================================================
class CCustomComponentsFactory : public ads::CDockComponentsFactory
{
public:
using Super = ads::CDockComponentsFactory;
ads::CDockAreaTitleBar* createDockAreaTitleBar(ads::CDockAreaWidget* DockArea) const override
{
auto TitleBar = new ads::CDockAreaTitleBar(DockArea);
auto CustomButton = new QToolButton(DockArea);
CustomButton->setToolTip(QObject::tr("Help"));
CustomButton->setIcon(svgIcon(":/adsdemo/images/help_outline.svg"));
CustomButton->setAutoRaise(true);
int Index = TitleBar->indexOf(TitleBar->button(ads::TitleBarButtonTabsMenu));
TitleBar->insertWidget(Index + 1, CustomButton);
return TitleBar;
}
};
//============================================================================
static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
{
@@ -180,31 +206,46 @@ 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()});
auto a = OptionsMenu->addAction(QObject::tr("Clear Editor"));
w->connect(a, SIGNAL(triggered()), SLOT(clear()));
return DockWidget;
}
//============================================================================
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
{
static int TableCount = 0;
QTableWidget* w = new QTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
w->setColumnCount(colCount);
w->setRowCount(rowCount);
for (int col = 0; col < colCount; ++col)
{
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
for (int row = 0; row < rowCount; ++row)
{
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
}
}
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
static int TableCount = 0;
QTableWidget* w = new QTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
w->setColumnCount(colCount);
w->setRowCount(rowCount);
for (int col = 0; col < colCount; ++col)
{
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
for (int row = 0; row < rowCount; ++row)
{
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
}
}
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
ViewMenu->addAction(DockWidget->toggleViewAction());
return DockWidget;
}
@@ -268,7 +309,6 @@ struct MainWindowPrivate
void restorePerspectives();
};
//============================================================================
void MainWindowPrivate::createContent()
{
@@ -276,12 +316,23 @@ void MainWindowPrivate::createContent()
QMenu* ViewMenu = ui.menuView;
auto DockWidget = createCalendarDockWidget(ViewMenu);
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
DockWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
DockWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
auto SpecialDockArea = DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
// For this Special Dock Area we want to avoid dropping on the center of it (i.e. we don't want this widget to be ever tabbified):
{
SpecialDockArea->setAllowedAreas(ads::OuterDockAreas);
//SpecialDockArea->setAllowedAreas({ads::LeftDockWidgetArea, ads::RightDockWidgetArea}); // just for testing
}
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
auto ToolBar = FileSystemWidget->createDefaultToolBar();
ToolBar->addAction(ui.actionSaveState);
ToolBar->addAction(ui.actionRestoreState);
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
appendFeaturStringToWindowTitle(FileSystemWidget);
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
@@ -291,11 +342,37 @@ void MainWindowPrivate::createContent()
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
appendFeaturStringToWindowTitle(FileSystemWidget);
// Test custom factory - we inject a help button into the title bar
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
ads::CDockComponentsFactory::resetDefaultFactory();
// We create a calendar widget and clear all flags to prevent the dock area
// from closing
DockWidget = createCalendarDockWidget(ViewMenu);
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
DockWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
DockWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
DockWidget->setTabToolTip(QString("Tab ToolTip\nHodie est dies magna"));
DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
auto DockArea = DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
// Now we add a custom button to the dock area title bar that will create
// new editor widgets when clicked
auto CustomButton = new QToolButton(DockArea);
CustomButton->setToolTip(QObject::tr("Create Editor"));
CustomButton->setIcon(svgIcon(":/adsdemo/images/plus.svg"));
CustomButton->setAutoRaise(true);
auto TitleBar = DockArea->titleBar();
int Index = TitleBar->indexOf(TitleBar->tabBar());
TitleBar->insertWidget(Index + 1, CustomButton);
QObject::connect(CustomButton, &QToolButton::clicked, [=]()
{
auto DockWidget = createEditorWidget(ui.menuView);
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
DockManager->addDockWidgetTabToArea(DockWidget, DockArea);
_this->connect(DockWidget, SIGNAL(closeRequested()), SLOT(onEditorCloseRequested()));
});
// Test dock area docking
auto RighDockArea = DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);
@@ -402,20 +479,41 @@ CMainWindow::CMainWindow(QWidget *parent) :
{
using namespace ads;
d->ui.setupUi(this);
d->createActions();
// uncomment the following line if the tab close button should be
// a QToolButton instead of a QPushButton
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
// comment the following line if you want to use opaque undocking and
// uncomment the following line if you want to use opaque undocking and
// opaque splitter resizing
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
// uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes
//CDockManager::setConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden, true);
// uncomment the following line if you don't want close button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasCloseButton, false);
// uncomment the following line if you don't want undock button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasUndockButton, false);
// uncomment the following line if you don't want tabs menu button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasTabsMenuButton, false);
// uncomment the following line if you don't want disabled buttons to appear on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHideDisabledButtons, true);
// uncomment the following line if you want to show tabs menu button on DockArea's title bar only when there are more than one tab and at least of them has elided title
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
// uncomment the following line if you want floating container to always show application title instead of active dock widget's title
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false);
// uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true);
// Now create the dock manager and its content
d->DockManager = new CDockManager(this);

4
demo/app.css Normal file
View File

@@ -0,0 +1,4 @@
ads--CTitleBarButton::menu-indicator
{
image: none;
}

505
demo/demo.py Normal file
View File

@@ -0,0 +1,505 @@
import datetime
import logging
import os
import sys
from PyQt5 import uic
from PyQt5.QtCore import (QCoreApplication, QDir, Qt, QSettings, QSignalBlocker,
QRect, QPoint, qDebug, qInstallMessageHandler,
QtDebugMsg, QtInfoMsg, QtWarningMsg,
QtCriticalMsg, QtFatalMsg)
from PyQt5.QtGui import (QGuiApplication, QIcon, QCloseEvent)
from PyQt5.QtWidgets import (QCalendarWidget, QFileSystemModel, QFrame, QLabel,
QMenu, QTreeView, QAction, QWidgetAction,
QComboBox, QStyle, QSizePolicy, QInputDialog, QMenu,
QToolButton, QWidget, QPlainTextEdit,
QTableWidget, QTableWidgetItem, QApplication,
QMessageBox)
try:
from PyQt5.QAxContainer import QAxWidget
except ImportError:
ACTIVEX_AVAILABLE = False
else:
ACTIVEX_AVAILABLE = True
from PyQtAds import QtAds
import rc # pyrcc5 demo.qrc -o rc.py
UI_FILE = os.path.join(os.path.dirname(__file__), 'mainwindow.ui')
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
class _State:
label_count = 0
calendar_count = 0
file_system_count = 0
editor_count = 0
table_count = 0
activex_count = 0
def features_string(dock_widget: QtAds.CDockWidget) -> str:
'''Function returns a features string with closable (c), movable (m) and floatable (f)
features. i.e. The following string is for a not closable but movable and floatable
widget: c- m+ f+'''
f = dock_widget.features()
closable = f & QtAds.CDockWidget.DockWidgetClosable
movable = f & QtAds.CDockWidget.DockWidgetMovable
floatable = f &QtAds.CDockWidget.DockWidgetFloatable
return "c{} m{} f{}".format("+" if closable else "-",
"+" if movable else "-",
"+" if floatable else "-")
def append_feature_string_to_window_title(dock_widget: QtAds.CDockWidget):
'''Appends the string returned by features_string() to the window title of
the given DockWidget'''
dock_widget.setWindowTitle(dock_widget.windowTitle() + " ({})".format(features_string(dock_widget)))
def svg_icon(filename: str):
'''Helper function to create an SVG icon'''
# This is a workaround, because because in item views SVG icons are not
# properly scaled an look blurry or pixelate
icon = QIcon(filename)
icon.addPixmap(icon.pixmap(92))
return icon
def create_long_text_label_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
label = QLabel()
label.setWordWrap(True)
label.setAlignment(Qt.AlignTop | Qt.AlignLeft)
label.setText('''\
Label {} {} - Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum
sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla
vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut,
imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis
pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.
Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu,
consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra
quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
'''.format(_State.label_count, datetime.datetime.now().strftime("%H:%M:%S:%f")))
dock_widget = QtAds.CDockWidget("Label {}".format(_State.label_count))
_State.label_count += 1
dock_widget.setWidget(label)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
def create_calendar_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
widget = QCalendarWidget()
dock_widget = QtAds.CDockWidget("Calendar {}".format(_State.calendar_count))
_State.calendar_count += 1
dock_widget.setWidget(widget)
dock_widget.setToggleViewActionMode(QtAds.CDockWidget.ActionModeShow)
dock_widget.setIcon(svg_icon(":/adsdemo/images/date_range.svg"))
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
def create_file_system_tree_dock_widget(view_menu: QMenu) -> QtAds.CDockWidget:
widget = QTreeView()
widget.setFrameShape(QFrame.NoFrame)
m = QFileSystemModel(widget)
m.setRootPath(QDir.currentPath())
widget.setModel(m)
dock_widget = QtAds.CDockWidget("Filesystem {}".format(_State.file_system_count))
_State.file_system_count += 1
dock_widget.setWidget(widget)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
def create_editor_widget(view_menu: QMenu) -> QtAds.CDockWidget:
widget = QPlainTextEdit()
widget.setPlaceholderText("This is an editor. If you close the editor, it will be "
"deleted. Enter your text here.")
widget.setStyleSheet("border: none")
dock_widget = QtAds.CDockWidget("Editor {}".format(_State.editor_count))
_State.editor_count += 1
dock_widget.setWidget(widget)
dock_widget.setIcon(svg_icon(":/adsdemo/images/edit.svg"))
dock_widget.setFeature(QtAds.CDockWidget.CustomCloseHandling, True)
view_menu.addAction(dock_widget.toggleViewAction())
options_menu = QMenu(dock_widget)
options_menu.setTitle("Options")
options_menu.setToolTip(options_menu.title())
options_menu.setIcon(svg_icon(":/adsdemo/images/custom-menu-button.svg"))
menu_action = options_menu.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
menu_action.setObjectName("options_menu")
dock_widget.setTitleBarActions([options_menu.menuAction()])
a = options_menu.addAction("Clear Editor")
a.triggered.connect(widget.clear)
return dock_widget
def create_table_widget(view_menu: QMenu) -> QtAds.CDockWidget:
widget = QTableWidget()
dock_widget = QtAds.CDockWidget("Table {}".format(_State.table_count))
_State.table_count += 1
COLCOUNT = 5
ROWCOUNT = 30
widget.setColumnCount(COLCOUNT)
widget.setRowCount(ROWCOUNT)
for col in range(ROWCOUNT):
widget.setHorizontalHeaderItem(col, QTableWidgetItem("Col {}".format(col+1)))
for row in range(ROWCOUNT):
widget.setItem(row, col, QTableWidgetItem("T {:}-{:}".format(row+1, col+1)))
dock_widget.setWidget(widget)
dock_widget.setIcon(svg_icon(":/adsdemo/images/grid_on.svg"))
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
if ACTIVEX_AVAILABLE:
def create_activex_widget(view_menu: QMenu, parent: QWidget = None) -> QtAds.CDockWidget:
widget = QAxWidget("{6bf52a52-394a-11d3-b153-00c04f79faa6}", parent)
dock_widget = QtAds.CDockWidget("Active X {}".format(_State.activex_count))
_State.activex_count += 1
dock_widget.setWidget(widget)
view_menu.addAction(dock_widget.toggleViewAction())
return dock_widget
class CustomComponentsFactory(QtAds.CDockComponentsFactory):
def createDockAreaTitleBar(self, dock_area: QtAds.CDockAreaWidget) -> QtAds.CDockAreaTitleBar:
title_bar = QtAds.CDockAreaTitleBar(dock_area)
custom_button = QToolButton(dock_area)
custom_button.setToolTip("Help")
custom_button.setIcon(svg_icon(":/adsdemo/images/help_outline.svg"))
custom_button.setAutoRaise(True)
index = title_bar.indexOf(title_bar.button(QtAds.TitleBarButtonTabsMenu))
title_bar.insertWidget(index + 1, custom_button)
return title_bar
class MainWindow(MainWindowUI, MainWindowBase):
save_perspective_action: QAction
perspective_list_action: QWidgetAction
perspective_combo_box: QComboBox
dock_manager: QtAds.CDockManager
def __init__(self, parent=None):
super().__init__(parent)
self.save_perspective_action = None
self.perspective_list_action = None
self.perspective_combo_box = None
self.dock_manager = None
self.setupUi(self)
self.create_actions()
# uncomment the following line if the tab close button should be
# a QToolButton instead of a QPushButton
# QtAds.CDockManager.setConfigFlags(QtAds.CDockManager.configFlags() | QtAds.CDockManager.TabCloseButtonIsToolButton)
# uncomment the following line if you want a fixed tab width that does
# not change if the visibility of the close button changes
# QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.RetainTabSizeWhenCloseButtonHidden, True)
# uncomment the follwing line if you want to use non opaque undocking and splitter
# movements
# QtAds.CDockManager.setConfigFlags(QtAds.CDockManager.DefaultNonOpaqueConfig)
# Now create the dock manager and its content
self.dock_manager = QtAds.CDockManager(self)
# Uncomment the following line to have the old style where the dock
# area close button closes the active tab
# QtAds.CDockManager.setConfigFlags(QtAds.CDockManager.DockAreaHasCloseButton
# | QtAds.CDockManager.DockAreaCloseButtonClosesTab)
self.perspective_combo_box.activated[str].connect(self.dock_manager.openPerspective)
self.create_content()
# Default window geometry - center on screen
self.resize(1280, 720)
self.setGeometry(QStyle.alignedRect(
Qt.LeftToRight, Qt.AlignCenter, self.frameSize(),
QGuiApplication.primaryScreen().availableGeometry()))
# self.restore_state()
self.restore_perspectives()
def create_content(self):
# Test container docking
view_menu = self.menuView
dock_widget = create_calendar_dock_widget(view_menu)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetClosable, False)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetMovable, False)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetFloatable, False)
special_dock_area = self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, dock_widget)
# For this Special Dock Area we want to avoid dropping on the center of it (i.e. we don't want this widget to be ever tabbified):
special_dock_area.setAllowedAreas(QtAds.OuterDockAreas)
# special_dock_area.setAllowedAreas(QtAds.LeftDockWidgetArea | QtAds.RightDockWidgetArea) # just for testing
self.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, create_long_text_label_dock_widget(view_menu))
file_system_widget = create_file_system_tree_dock_widget(view_menu)
tool_bar = file_system_widget.createDefaultToolBar()
tool_bar.addAction(self.actionSaveState)
tool_bar.addAction(self.actionRestoreState)
file_system_widget.setFeature(QtAds.CDockWidget.DockWidgetFloatable, False)
append_feature_string_to_window_title(file_system_widget)
self.dock_manager.addDockWidget(QtAds.BottomDockWidgetArea, file_system_widget)
file_system_widget = create_file_system_tree_dock_widget(view_menu)
tool_bar = file_system_widget.createDefaultToolBar()
tool_bar.addAction(self.actionSaveState)
tool_bar.addAction(self.actionRestoreState)
file_system_widget.setFeature(QtAds.CDockWidget.DockWidgetMovable, False)
file_system_widget.setFeature(QtAds.CDockWidget.DockWidgetFloatable, False)
append_feature_string_to_window_title(file_system_widget)
# Test custom factory - we inject a help button into the title bar
self.factory = CustomComponentsFactory()
QtAds.CDockComponentsFactory.setFactory(self.factory)
top_dock_area = self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, file_system_widget)
QtAds.CDockComponentsFactory.resetDefaultFactory()
# We create a calendar widget and clear all flags to prevent the dock area
# from closing
dock_widget = create_calendar_dock_widget(view_menu)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetClosable, False)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetMovable, False)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetFloatable, False)
dock_widget.setTabToolTip("Tab ToolTip\nHodie est dies magna")
dock_area = self.dock_manager.addDockWidget(QtAds.CenterDockWidgetArea, dock_widget, top_dock_area)
# Now we add a custom button to the dock area title bar that will create
# new editor widgets when clicked
custom_button = QToolButton(dock_area)
custom_button.setToolTip("Create Editor")
custom_button.setIcon(svg_icon(":/adsdemo/images/plus.svg"))
custom_button.setAutoRaise(True)
title_bar = dock_area.titleBar()
index = title_bar.indexOf(title_bar.tabBar())
title_bar.insertWidget(index + 1, custom_button)
def on_button_clicked():
dock_widget = create_editor_widget(self.menuView)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
self.dock_manager.addDockWidgetTabToArea(dock_widget, dock_area)
dock_widget.closeRequested.connect(self.on_editor_close_requested)
custom_button.clicked.connect(on_button_clicked)
# Test dock area docking
right_dock_area = self.dock_manager.addDockWidget(
QtAds.RightDockWidgetArea,
create_long_text_label_dock_widget(view_menu), top_dock_area)
self.dock_manager.addDockWidget(
QtAds.TopDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
bottom_dock_area = self.dock_manager.addDockWidget(
QtAds.BottomDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
self.dock_manager.addDockWidget(
QtAds.CenterDockWidgetArea,
create_long_text_label_dock_widget(view_menu), right_dock_area)
self.dock_manager.addDockWidget(
QtAds.CenterDockWidgetArea,
create_long_text_label_dock_widget(view_menu), bottom_dock_area)
action = self.menuView.addAction("Set {} floating".format(dock_widget.windowTitle()))
action.triggered.connect(dock_widget.setFloating)
if ACTIVEX_AVAILABLE:
flags = self.dock_manager.configFlags()
if flags & QtAds.CDockManager.OpaqueUndocking:
self.dock_manager.addDockWidget(QtAds.CenterDockWidgetArea,
create_activex_widget(view_menu), right_dock_area)
for dock_widget in self.dock_manager.dockWidgetsMap().values():
dock_widget.viewToggled.connect(self.on_view_toggled)
dock_widget.visibilityChanged.connect(self.on_view_visibility_changed)
def create_actions(self):
self.toolBar.addAction(self.actionSaveState)
self.toolBar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.actionSaveState.setIcon(svg_icon(":/adsdemo/images/save.svg"))
self.toolBar.addAction(self.actionRestoreState)
self.actionRestoreState.setIcon(svg_icon(":/adsdemo/images/restore.svg"))
self.save_perspective_action = QAction("Create Perspective", self)
self.save_perspective_action.setIcon(svg_icon(":/adsdemo/images/picture_in_picture.svg"))
self.save_perspective_action.triggered.connect(self.save_perspective)
self.perspective_list_action = QWidgetAction(self)
self.perspective_combo_box = QComboBox(self)
self.perspective_combo_box.setSizeAdjustPolicy(QComboBox.AdjustToContents)
self.perspective_combo_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.perspective_list_action.setDefaultWidget(self.perspective_combo_box)
self.toolBar.addSeparator()
self.toolBar.addAction(self.perspective_list_action)
self.toolBar.addAction(self.save_perspective_action)
a = self.toolBar.addAction("Create Editor")
a.setToolTip("Creates floating dynamic dockable editor windows that are deleted on close")
a.setIcon(svg_icon(":/adsdemo/images/note_add.svg"))
a.triggered.connect(self.create_editor)
a = self.toolBar.addAction("Create Table")
a.setToolTip("Creates floating dynamic dockable table with millions of entries")
a.setIcon(svg_icon(":/adsdemo/images/grid_on.svg"))
a.triggered.connect(self.create_table)
def closeEvent(self, event: QCloseEvent):
self.save_state()
super().closeEvent(event)
def on_action_save_state_triggered(state: bool):
qDebug("MainWindow::on_action_save_state_triggered")
self.save_state()
def on_action_restore_state_triggered(state: bool):
qDebug("MainWindow::on_action_restore_state_triggered")
self.restore_state()
def save_perspective(self):
perspective_name, ok = QInputDialog.getText(self, "Save perspective",
"Enter unique name:")
if ok and perspective_name:
self.dock_manager.addPerspective(perspective_name)
_ = QSignalBlocker(self.perspective_combo_box)
self.perspective_combo_box.clear()
self.perspective_combo_box.addItems(self.dock_manager.perspectiveNames())
self.perspective_combo_box.setCurrentText(perspective_name)
self.save_perspectives()
def on_view_toggled(self, open: bool):
dock_widget = self.sender()
if dock_widget is None:
return
qDebug("{} view_toggled({})".format(dock_widget.objectName(), open))
def on_view_visibility_changed(self, visible: bool):
dock_widget = self.sender()
if dock_widget is None:
return
qDebug("{} visibility_changed({})".format(dock_widget.objectName(), visible))
def create_editor(self):
dock_widget = create_editor_widget(self.menuView)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
floating_widget = self.dock_manager.addDockWidgetFloating(dock_widget)
floating_widget.move(QPoint(20, 20))
dock_widget.closeRequested.connect(self.on_editor_close_requested)
def on_editor_close_requested(self):
dock_widget = self.sender()
result = QMessageBox.question(self, "Close Editor",
"Editor {} contains unsaved changes? Would you like to close it?".format(dock_widget.windowTitle()))
if result == QMessageBox.Yes:
dock_widget.closeDockWidget()
def create_table(self):
dock_widget = create_table_widget(self.menuView)
dock_widget.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
floating_widget = self.dock_manager.addDockWidgetFloating(dock_widget)
floating_widget.move(QPoint(40, 40))
def save_state(self):
'''
Saves the dock manager state and the main window geometry
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
settings.setValue("mainWindow/Geometry", self.saveGeometry())
settings.setValue("mainWindow/State", self.saveState())
settings.setValue("mainWindow/DockingState", self.dock_manager.saveState())
def restore_state(self):
'''
Restores the dock manager state
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
geom = settings.value("mainWindow/Geometry")
if geom is not None:
self.restoreGeometry(geom)
state = settings.value("mainWindow/State")
if state is not None:
self.restoreState(state)
state = settings.value("mainWindow/DockingState")
if state is not None:
self.dock_manager.restore_state(state)
def save_perspectives(self):
'''
Save the list of perspectives
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
self.dock_manager.savePerspectives(settings)
def restore_perspectives(self):
'''
Restore the perspective listo of the dock manager
'''
settings = QSettings("Settings.ini", QSettings.IniFormat)
self.dock_manager.loadPerspectives(settings)
self.perspective_combo_box.clear()
self.perspective_combo_box.addItems(self.dock_manager.perspectiveNames())
def save_perspective(self):
perspective_name, ok = QInputDialog.getText(self, 'Save perspective', 'Enter unique name:')
if ok and perspective_name:
self.dock_manager.addPerspective(perspective_name)
_ = QSignalBlocker(self.perspective_combo_box)
self.perspective_combo_box.clear()
self.perspective_combo_box.addItems(self.dock_manager.perspectiveNames())
self.perspective_combo_box.setCurrentText(perspective_name)
self.save_perspectives()
def my_message_output(type, context, msg):
if type == QtDebugMsg:
print("Debug: {} ({}:{}, {})".format(msg, context.file, context.line, context.function))
elif type == QtInfoMsg:
print("Info: {} ({}:{}, {})".format(msg, context.file, context.line, context.function))
elif type == QtWarningMsg:
print("Warning: {} ({}:{}, {})".format(msg, context.file, context.line, context.function))
elif type == QtCriticalMsg:
print("Critical: {} ({}:{}, {})".format(msg, context.file, context.line, context.function))
elif type == QtFatalMsg:
print("Fatal: {} ({}:{}, {})".format(msg, context.file, context.line, context.function))
if __name__ == '__main__':
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)
with open(os.path.join(os.path.dirname(__file__), "app.css"), "r") as style_sheet_file:
app.setStyleSheet(style_sheet_file.read())
qInstallMessageHandler(my_message_output)
qDebug("Message handler test")
mw = MainWindow()
mw.show()
app.exec_()

View File

@@ -9,5 +9,9 @@
<file>images/date_range.svg</file>
<file>images/edit.svg</file>
<file>images/grid_on.svg</file>
<file>images/custom-menu-button.svg</file>
<file>app.css</file>
<file>images/plus.svg</file>
<file>images/help_outline.svg</file>
</qresource>
</RCC>

View 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

View File

@@ -0,0 +1,6 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,1024,1024">
<desc>help_outline icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.)</desc>
<g fill="#03b8e5" fill-rule="nonzero" style="mix-blend-mode: normal">
<path d="M938.67,512c0,235.52 -191.15,426.67 -426.67,426.67c-235.52,0 -426.67,-191.15 -426.67,-426.67c0,-235.52 191.15,-426.67 426.67,-426.67c235.52,0 426.67,191.15 426.67,426.67zM853.33,512c0,-188.16 -153.17,-341.33 -341.33,-341.33c-188.16,0 -341.33,153.17 -341.33,341.33c0,188.16 153.17,341.33 341.33,341.33c188.16,0 341.33,-153.17 341.33,-341.33zM682.67,426.67c0,106.67 -128,117.33 -128,213.33h-85.34c0,-138.67 128,-128 128,-213.33c0,-46.93 -38.4,-85.34 -85.33,-85.34c-46.93,0 -85.33,38.41 -85.33,85.34h-85.34c0,-94.29 76.38,-170.67 170.67,-170.67c94.29,0 170.67,76.38 170.67,170.67zM469.33,682.67h85.34v85.33h-85.34z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

123
demo/images/plus.svg Normal file
View File

@@ -0,0 +1,123 @@
<?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.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="plus.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="-2.5629517"
inkscape:cy="7.4271635"
inkscape:document-units="px"
inkscape:current-layer="g5228"
showgrid="true"
units="px"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1912"
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="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m -620.5,1189.8622 v -11"
id="path822-5"
inkscape:connector-curvature="0" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m -615,1184.3622 h -11"
id="path822-5-2"
inkscape:connector-curvature="0" />
</g>
</g>
<metadata
id="metadata12">
<rdf:RDF>
<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>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -42,6 +42,13 @@ int main(int argc, char *argv[])
std::shared_ptr<int> b;
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(true);
QFile StyleSheetFile(":/adsdemo/app.css");
StyleSheetFile.open(QIODevice::ReadOnly);
QTextStream StyleSheetStream(&StyleSheetFile);
a.setStyleSheet(StyleSheetStream.readAll());
StyleSheetFile.close();
qInstallMessageHandler(myMessageOutput);
qDebug() << "Message handler test";

123
doc/ads_icon.svg Normal file
View File

@@ -0,0 +1,123 @@
<?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"
version="1.1"
viewBox="0,0,1024,1024"
id="svg1145"
sodipodi:docname="ads_icon.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
inkscape:export-filename="C:\CodingXP\cetoni_projects\QtAdvancedDockingSystem\doc\ads_icon_256.png"
inkscape:export-xdpi="24"
inkscape:export-ydpi="24">
<metadata
id="metadata1151">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs1149" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1017"
id="namedview1147"
showgrid="false"
inkscape:zoom="0.32593202"
inkscape:cx="256.13402"
inkscape:cy="235.82602"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg1145" />
<desc
id="desc1129">window_size icon - Licensed under Iconfu Standard License v1.0 (https://www.iconfu.com/iconfu_standard_license) - Incors GmbH</desc>
<path
id="path1797-1"
visibility="hidden"
d="M 71.53142,291.89723 H 950.1828 l 0.6743,0.6742 v 586.08 l -0.6743,0.6743 H 71.53142 l -0.6743,-0.6743 v -586.08 z"
inkscape:connector-curvature="0"
style="visibility:hidden;mix-blend-mode:normal;fill:#ffffff;fill-rule:nonzero;stroke-width:0.99999988;fill-opacity:1" />
<rect
transform="rotate(-90)"
y="412.13489"
x="-911.34436"
height="560.90375"
width="327.70862"
id="rect1739-8"
style="opacity:1;fill:#ffd292;fill-opacity:1;stroke:none;stroke-width:37.79526901;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" />
<path
id="path1799"
d="M 988.40121,578.11175 V 651.2546 H 409.96541 V 578.11175 Z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#546e7a;fill-rule:nonzero;stroke-width:0.99999988" />
<rect
style="opacity:1;fill:#b3c3cb;fill-opacity:1;stroke:none;stroke-width:37.79526901;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
id="rect1739-6-1"
width="655.41724"
height="338.99207"
x="-914.85529"
y="38.243896"
transform="rotate(-90)" />
<path
id="path1801-7"
d="m 73.1429,73.14287 h 877.7142 c 40.2857,0 73.1429,32.86857 73.1429,73.14285 V 914.2857 c 0,20.12571 -16.4458,36.57142 -36.5715,36.57142 H 36.5714 C 16.4343,950.85712 0,934.42284 0,914.2857 V 146.28572 C 0,106.00001 32.8571,73.14287 73.1429,73.14287 Z m 0,219.42856 V 877.71427 H 950.8571 V 292.57143 Z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#546e7a;fill-rule:nonzero;stroke-width:0.99999988" />
<path
id="path1799-6"
d="M 359.8801,276.79402 H 433.023 V 886.78767 H 359.8801 Z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#546e7a;fill-rule:nonzero;stroke-width:0.99999988" />
<circle
r="36.81749"
cy="169.78555"
cx="920.66248"
id="path1917-42"
style="opacity:1;fill:#ffa726;fill-opacity:1;stroke:none;stroke-width:63.79999924;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers" />
<circle
r="36.81749"
cy="169.78555"
cx="817.22302"
id="path1917-4-6"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:63.79999924;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers" />
<path
id="path1799-8"
d="m 615.67076,292.13464 v 73.14285 H 433.023 v -73.14285 z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#95abb6;fill-rule:nonzero;stroke-width:0.99999994;fill-opacity:1" />
<path
id="path1799-8-1"
d="m 798.31852,292.13464 v 73.14285 H 615.67076 v -73.14285 z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#c7d4d9;fill-rule:nonzero;stroke-width:0.99999994;fill-opacity:1" />
<path
id="path1799-8-7"
d="m 255.79066,292.57143 v 73.14285 H 73.1429 v -73.14285 z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#dfe5e9;fill-opacity:1;fill-rule:nonzero;stroke-width:0.99999994" />
<path
id="path1799-8-7-6"
d="m 616.34083,651.15739 v 73.14285 H 433.69307 v -73.14285 z"
inkscape:connector-curvature="0"
style="mix-blend-mode:normal;fill:#ffba56;fill-opacity:1;fill-rule:nonzero;stroke-width:0.99999994" />
</svg>

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
doc/ads_icon_256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
doc/ads_icon_512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@@ -0,0 +1,109 @@
# Advanced Docking System for Qt
Qt Advanced Docking System lets you create customizable layouts using a full
featured window docking system similar to what is found in many popular
integrated development environments (IDEs) such as Visual Studio.
[![Video Advanced Docking](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/advanced-docking_video.png)](https://www.youtube.com/watch?v=7pdNfafg3Qc)
Everything is implemented with standard Qt functionality without any
platform specific code. Basic usage of QWidgets and QLayouts and using basic
styles as much as possible.
## Features
### Overview
- [Advanced Docking System for Qt](#advanced-docking-system-for-qt)
- [Features](#features)
- [Overview](#overview)
- [Docking everywhere - no central widget](#docking-everywhere---no-central-widget)
- [Docking inside floating windows](#docking-inside-floating-windows)
- [Grouped dragging](#grouped-dragging)
- [Perspectives for fast switching of the complete main window layout](#perspectives-for-fast-switching-of-the-complete-main-window-layout)
- [Opaque and non-opaque splitter resizing](#opaque-and-non-opaque-splitter-resizing)
- [Opaque and non-opaque undocking](#opaque-and-non-opaque-undocking)
- [Tab-menu for easy handling of many tabbed dock widgets](#tab-menu-for-easy-handling-of-many-tabbed-dock-widgets)
- [Many different ways to detach dock widgets](#many-different-ways-to-detach-dock-widgets)
- [Supports deletion of dynamically created dock widgets](#supports-deletion-of-dynamically-created-dock-widgets)
### Docking everywhere - no central widget
There is no central widget like in the Qt docking system. You can dock on every
border of the main window or you can dock into each dock area - so you are
free to dock almost everywhere.
![Dropping widgets](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/preview-dragndrop.png)\
\
![Dropping widgets](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/preview-dragndrop_dark.png)
### Docking inside floating windows
There is no difference between the main window and a floating window. Docking
into floating windows is supported.
![Docking inside floating windows](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/floating-widget-dragndrop.png)\
\
![Docking inside floating windows](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/floating-widget-dragndrop_dark.png)
### Grouped dragging
When dragging the titlebar of a dock, all the tabs that are tabbed with it are
going to be dragged. So you can move complete groups of tabbed widgets into
a floating widget or from one dock area to another one.
![Grouped dragging](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/grouped-dragging.gif)\
\
![Grouped dragging](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/grouped-dragging_dark.png)
### Perspectives for fast switching of the complete main window layout
A perspective defines the set and layout of dock windows in the main
window. You can save the current layout of the dockmanager into a named
perspective to make your own custom perspective. Later you can simply
select a perspective from the perspective list to quickly switch the complete
main window layout.
![Perspective](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/perspectives.gif)\
\
![Perspective](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/perspectives_dark.png)
### Opaque and non-opaque splitter resizing
The advanced docking system uses standard QSplitters as resize separators and thus supports opaque and non-opaque resizing functionality of QSplitter. In some rare cases, for very complex widgets or on slow machines resizing via separator on the fly may cause flicking and glaring of rendered content inside a widget. The global dock manager flag `OpaqueSplitterResize` configures the resizing behaviour of the splitters. If this flag is set, then widgets are resized dynamically (opaquely) while interactively moving the splitters.
![Opaque resizing](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/opaque_resizing.gif)
If this flag is cleared, the widget resizing is deferred until the mouse button is released - this is some kind of lazy resizing separator.
![Non-opaque resizing](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/non_opaque_resizing.gif)
### Opaque and non-opaque undocking
By default, opaque undocking is active. That means, as soon as you drag a dock widget or a dock area with a number of dock widgets it will be undocked and moved into a floating widget and then the floating widget will be dragged around. That means undocking will take place immediatelly. You can compare this with opaque splitter resizing. If the flag `OpaqueUndocking` is cleared, then non-opaque undocking is active. In this mode, undocking is more like a standard drag and drop operation. That means, the dragged dock widget or dock area is not undocked immediatelly. Instead, a drag preview widget is created and dragged around to indicate the future position of the dock widget or dock area. The actual dock operation is only executed when the mouse button is released. That makes it possible, to cancel an active drag operation with the escape key.
The drag preview widget can be configured by a number of global dock manager flags:
- `DragPreviewIsDynamic`: if this flag is enabled, the preview will be adjusted dynamically to the drop area
- `DragPreviewShowsContentPixmap`: the created drag preview window shows a static copy of the content of the dock widget / dock are that is dragged
- `DragPreviewHasWindowFrame`: this flag configures if the drag preview is frameless like a QRubberBand or looks like a real window
The best way to test non-opaque undocking is to set the standard flags: `CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig)`.
### Tab-menu for easy handling of many tabbed dock widgets
Tabs are a good way to quickly switch between dockwidgets in a dockarea. However, if the number of dockwidgets in a dockarea is too large, this may affect the usability of the tab bar. To keep track in this situation, you can use the tab menu. The menu allows you to quickly select the dockwidget you want to activate from a drop down menu.
![Tab menu](https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/tab_menu.gif)
### Many different ways to detach dock widgets
You can detach dock widgets and also dock areas in the following ways:
- by dragging the dock widget tab or the dock area title bar
- by double clicking the tab or title bar
- by using the detach menu entry from the tab and title bar drop down menu
### Supports deletion of dynamically created dock widgets
Normally clicking the close button of a dock widget will just hide the widget and the user can show it again using the toggleView() action of the dock widget. This is meant for user interfaces with a static amount of widgets. But the advanced docking system also supports dynamic dock widgets that will get deleted on close. If you set the dock widget flag `DockWidgetDeleteOnClose` for a certain dock widget, then it will be deleted as soon as you close this dock widget. This enables the implementation of user interfaces with dynamically created editors, like in word processing applications or source code development tools.

View File

@@ -0,0 +1,30 @@
{
"$schema": "http://qt.io/schema/extension-schema-v1#",
"title": "Qt Advanced Docking System",
"extensionType": [
"library"
],
"version": "3.0.0",
"vendor": {
"name": "githubuser0xFFFF",
"url": "https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System"
},
"contact": "https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues",
"icon": "https://raw.githubusercontent.com/githubuser0xFFFF/Qt-Advanced-Docking-System/master/doc/ads_icon_512.png",
"licenses": [
{ "licenseType": "LGPLv2.1",
"licenseUrl": "https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" }
],
"created": "2017-03-30",
"lastUpdate": "2020-01-16",
"platforms": [
"Windows 7-10", "Kubuntu 18.04", "Kubuntu 19.10", "Ubuntu 19.10"
],
"qtVersions": [
"5.5.1 or newer"
],
"tags": [
"Widgets", "Docking"],
"bugUrl": "https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues",
"sourceRepoUrl": "https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System"
}

BIN
doc/donate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

52
example/example.py Normal file
View File

@@ -0,0 +1,52 @@
import datetime
import logging
import os
import sys
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel
from PyQtAds import QtAds
UI_FILE = os.path.join(os.path.dirname(__file__), 'MainWindow.ui')
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE)
class MainWindow(MainWindowUI, MainWindowBase):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# Create the dock manager. Because the parent parameter is a QMainWindow
# the dock manager registers itself as the central widget.
self.dock_manager = QtAds.CDockManager(self)
# Create example content label - this can be any application specific
# widget
l = QLabel()
l.setWordWrap(True)
l.setAlignment(Qt.AlignTop | Qt.AlignLeft);
l.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ")
# Create a dock widget with the title Label 1 and set the created label
# as the dock widget content
dock_widget = QtAds.CDockWidget("Label 1")
dock_widget.setWidget(l)
# Add the toggleViewAction of the dock widget to the menu to give
# the user the possibility to show the dock widget if it has been closed
self.menuView.addAction(dock_widget.toggleViewAction())
# Add the dock widget to the top dock widget area
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()

View File

@@ -1,41 +0,0 @@
{% set data = load_setup_py_data() %}
package:
name: pyqtads
version: {{ data.get('version') }}
source:
path: ../
build:
number: 0
script: python setup.py install --single-version-externally-managed --record=record.txt --conda-recipe
requirements:
build:
- python
- setuptools
- pyqt>=5.9
- sip>=4.19
run:
- python
- pyqt>=5.9
- sip>=4.19
- pywin32 [win]
test:
imports:
- PyQtAds
about:
home: {{ data.get('url') }}
license: {{ data.get('license') }}
license_family: LGPL
license_file: 'LICENSE.md'
summary: {{ data.get('description') }}
description: {{ data.get('description') }}
doc_url: ''
dev_url: {{ data.get('url') }}
extra:
recipe-maintainers: 'nicolas.elie@cnrs.fr'

View File

@@ -18,7 +18,7 @@ from PyQt5.pyrcc_main import processResourceFile
MODULE_NAME = "ads"
SRC_PATH = "PyQtAds"
REQUIRE_PYQT = True
if "--conda-recipe" in sys.argv:
REQUIRE_PYQT = False
@@ -40,7 +40,7 @@ class HostPythonConfiguration(object):
else:
self.data_dir = sys.prefix + '/share'
self.lib_dir = sys.prefix + '/lib'
class TargetQtConfiguration(object):
def __init__(self, qmake):
@@ -63,12 +63,12 @@ class TargetQtConfiguration(object):
setattr(self, name, value)
pipe.close()
class build_ext(sipdistutils.build_ext):
description = "Builds the " + MODULE_NAME + " module."
user_options = sipdistutils.build_ext.user_options + [
('qmake-bin=', None, "Path to qmake binary"),
('sip-bin=', None, "Path to sip binary"),
@@ -78,7 +78,7 @@ class build_ext(sipdistutils.build_ext):
('sip-dir=', None, "Path to module's SIP files"),
('inc-dir=', None, "Path to module's include files")
]
def initialize_options (self):
super().initialize_options()
self.qmake_bin = 'qmake'
@@ -92,16 +92,16 @@ class build_ext(sipdistutils.build_ext):
self.inc_dir = None
self.pyconfig = HostPythonConfiguration()
self.qtconfig = TargetQtConfiguration(self.qmake_bin)
self.config = sipconfig.Configuration()
self.config = sipconfig.Configuration()
self.config.default_mod_dir = ("/usr/local/lib/python%i.%i/dist-packages" %
(sys.version_info.major, sys.version_info.minor))
def finalize_options (self):
super().finalize_options()
if not self.qt_include_dir:
self.qt_include_dir = self.qtconfig.QT_INSTALL_HEADERS
if not self.qt_libinfix:
try:
with open(os.path.join(self.qtconfig.QT_INSTALL_PREFIX, 'mkspecs', 'qconfig.pri'), 'r') as f:
@@ -113,16 +113,16 @@ class build_ext(sipdistutils.build_ext):
if not self.pyqt_sip_dir:
self.pyqt_sip_dir = os.path.join(self.pyconfig.data_dir, 'sip', 'PyQt5')
if not self.pyqt_sip_flags:
self.pyqt_sip_flags = PYQT_CONFIGURATION.get('sip_flags', '')
if not self.sip_files_dir:
self.sip_files_dir = os.path.abspath(os.path.join(".", "sip"))
if not self.sip_inc_dir:
self.sip_inc_dir = self.pyconfig.venv_inc_dir
if not self.inc_dir:
self.inc_dir = os.path.abspath(os.path.join(".", "src"))
@@ -138,12 +138,12 @@ class build_ext(sipdistutils.build_ext):
if not self.pyqt_sip_flags:
raise SystemExit('Could not find PyQt SIP flags. '
'Please specify via --pyqt-sip-flags=')
def _find_sip(self):
"""override _find_sip to allow for manually speficied sip path."""
return self.sip_bin or super()._find_sip()
def _sip_compile(self, sip_bin, source, sbf):
def _sip_compile(self, sip_bin, source, sbf):
cmd = [sip_bin]
if hasattr(self, 'sip_opts'):
cmd += self.sip_opts
@@ -157,11 +157,11 @@ class build_ext(sipdistutils.build_ext):
"-c", self._sip_output_dir(),
"-b", sbf,
"-w", "-o"]
cmd += shlex.split(self.pyqt_sip_flags) # use same SIP flags as for PyQt5
cmd.append(source)
self.spawn(cmd)
def swig_sources (self, sources, extension=None):
if not self.extensions:
return
@@ -179,7 +179,7 @@ class build_ext(sipdistutils.build_ext):
extension.libraries += ['Qt5Core' + self.qt_libinfix,
'Qt5Gui' + self.qt_libinfix,
'Qt5Widgets' + self.qt_libinfix]
if sys.platform == 'win32':
extension.library_dirs += [self.qtconfig.QT_INSTALL_LIBS,
self.inc_dir, self._sip_output_dir()]
@@ -192,30 +192,46 @@ class build_ext(sipdistutils.build_ext):
extension.extra_compile_args += ['-std=c++11']
return super().swig_sources(sources, extension)
def build_extension(self, ext):
cppsources = [source for source in ext.sources if source.endswith(".cpp")]
dir_util.mkpath(self.build_temp, dry_run=self.dry_run)
def get_moc_args(out_file, source):
if sys.platform.startswith('linux'):
return ["moc", "-D", "Q_OS_LINUX=1", "-o", out_file, source]
if sys.platform.startswith('darwin'):
return ["moc", "-D", "Q_OS_MACOS=1", "-o", out_file, source]
if sys.platform.startswith('win'):
return ["moc", "-D", "Q_OS_WIN=1", "-o", out_file, source]
return ["moc", "-o", out_file, source]
# Run moc on all header files.
for source in cppsources:
# *.cpp -> *.moc
moc_file = os.path.basename(source).replace(".cpp", ".moc")
out_file = os.path.join(self.build_temp, moc_file)
if newer(source, out_file) or self.force:
spawn.spawn(get_moc_args(out_file, source), dry_run=self.dry_run)
header = source.replace(".cpp", ".h")
if os.path.exists(header):
# *.h -> moc_*.cpp
moc_file = "moc_" + os.path.basename(header).replace(".h", ".cpp")
out_file = os.path.join(self.build_temp, moc_file)
if newer(header, out_file) or self.force:
call_arg = ["moc", "-o", out_file, header]
spawn.spawn(call_arg, dry_run=self.dry_run)
spawn.spawn(get_moc_args(out_file, header), dry_run=self.dry_run)
if os.path.getsize(out_file) > 0:
ext.sources.append(out_file)
# Add the temp build directory to include path, for compiler to find
# the created .moc files
ext.include_dirs += [self._sip_output_dir()]
sipdistutils.build_ext.build_extension(self, ext)
@@ -253,7 +269,7 @@ ext_modules = [Extension('PyQtAds.QtAds.ads', cpp_sources + sip_sources)]
install_requires = ["PyQt5"]
if sys.platform == 'win32':
install_requires.append("pywin32")
with open('README.md', 'r') as f:
LONG_DESCRIPTION = f.read()

View File

@@ -1,82 +0,0 @@
import logging
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import Qt
from PyQtAds import QtAds
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setup_ui()
self.dock_manager = QtAds.CDockManager(self)
self.dock_widgets = []
for label_text, area in (
('1 Top', QtAds.TopDockWidgetArea),
('2 Bottom', QtAds.BottomDockWidgetArea),
('3 Left', QtAds.LeftDockWidgetArea),
('4 Right', QtAds.RightDockWidgetArea),
):
# Create example content label - this can be any application specific
# widget
label = QtWidgets.QLabel()
label.setWordWrap(True)
label.setAlignment(Qt.AlignTop | Qt.AlignLeft)
label.setText(f"{label_text}: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ")
# Create a dock widget with the title Label 1 and set the created label
# as the dock widget content
dock_widget = QtAds.CDockWidget(label_text)
dock_widget.setWidget(label)
self.dock_widgets.append(dock_widget)
# Add the toggleViewAction of the dock widget to the menu to give
# the user the possibility to show the dock widget if it has been closed
self.menu_view.addAction(dock_widget.toggleViewAction())
# Add the dock widget to the top dock widget area
self.dock_manager.addDockWidget(area, dock_widget)
def setup_ui(self):
self.setWindowTitle("MainWindow")
self.setObjectName("MainWindow")
self.resize(400, 300)
self.central_widget = QtWidgets.QWidget(self)
self.central_widget.setObjectName("central_widget")
self.setCentralWidget(self.central_widget)
self.menu_bar = QtWidgets.QMenuBar(self)
self.menu_bar.setGeometry(QtCore.QRect(0, 0, 400, 21))
self.menu_bar.setObjectName("menuBar")
self.menu_view = QtWidgets.QMenu(self.menu_bar)
self.menu_view.setObjectName("menu_view")
self.menu_view.setTitle("View")
self.setMenuBar(self.menu_bar)
self.status_bar = QtWidgets.QStatusBar(self)
self.status_bar.setObjectName("statusBar")
self.setStatusBar(self.status_bar)
self.menu_bar.addAction(self.menu_view.menuAction())
def main(app):
main = MainWindow()
main.show()
state = main.dock_manager.saveState()
print('This is what the saved state looks like in XML:')
print(state)
print()
main.dock_manager.restoreState(state)
return main
if __name__ == '__main__':
logging.basicConfig(level='DEBUG')
app = QtWidgets.QApplication([])
window = main(app)
window.show()
print('shown')
app.exec_()

View File

@@ -13,14 +13,6 @@ class CDockAreaTabBar : QScrollArea
protected:
virtual void wheelEvent(QWheelEvent* Event);
virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseReleaseEvent(QMouseEvent* ev);
virtual void mouseMoveEvent(QMouseEvent* ev);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
void startFloating(const QPoint& Offset);
ads::IFloatingWidget* makeAreaFloating(const QPoint& Offset,
ads::eDragState DragState);
ads::eDragState dragState() const;
public:
CDockAreaTabBar(ads::CDockAreaWidget* parent /TransferThis/);
@@ -35,6 +27,7 @@ public:
bool isTabOpen(int Index) const;
virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;
void elidedChanged(bool elided);
public slots:
void setCurrentIndex(int Index);
@@ -54,4 +47,4 @@ signals:
};
%End
%End

View File

@@ -11,6 +11,13 @@ class CDockAreaTitleBar : QFrame
#include <DockAreaTitleBar.h>
%End
protected:
virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseReleaseEvent(QMouseEvent* ev);
virtual void mouseMoveEvent(QMouseEvent* ev);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *event);
public slots:
void markTabsMenuOutdated();
@@ -20,7 +27,10 @@ public:
virtual ~CDockAreaTitleBar();
ads::CDockAreaTabBar* tabBar() const;
QAbstractButton* button(ads::TitleBarButton which) const;
void updateDockWidgetActionsButtons();
virtual void setVisible(bool Visible);
void insertWidget(int index, QWidget *widget /Transfer/ );
int indexOf(QWidget *widget) const;
signals:

View File

@@ -42,12 +42,16 @@ public:
int currentIndex() const;
int indexOfFirstOpenDockWidget() const;
ads::CDockWidget* currentDockWidget() const;
void setCurrentDockWidget(ads::CDockWidget* DockWidget /Transfer/);
void setCurrentDockWidget(ads::CDockWidget* DockWidget);
void saveState(QXmlStreamWriter& Stream) const;
ads::CDockWidget::DockWidgetFeatures features() const;
ads::CDockWidget::DockWidgetFeatures features(ads::eBitwiseOperator Mode = ads::BitwiseAnd) const;
QAbstractButton* titleBarButton(ads::TitleBarButton which) const;
virtual void setVisible(bool Visible);
void setAllowedAreas(DockWidgetAreas areas);
DockWidgetAreas allowedAreas() const;
CDockAreaTitleBar* titleBar() const;
public slots:
void setCurrentIndex(int index);
void closeArea();

View File

@@ -0,0 +1,26 @@
%If (Qt_5_0_0 -)
namespace ads
{
class CDockComponentsFactory
{
%TypeHeaderCode
#include <DockComponentsFactory.h>
%End
public:
virtual ~CDockComponentsFactory();
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget /Transfer/ ) const;
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea /Transfer/ ) const;
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea /Transfer/ ) const;
static const CDockComponentsFactory* factory();
static void setFactory(CDockComponentsFactory* Factory);
static void resetDefaultFactory();
};
};
%End

View File

@@ -23,13 +23,12 @@ protected:
QSplitter* rootSplitter() const;
void createRootSplitter();
void dropFloatingWidget(ads::CFloatingDockContainer* FloatingWidget, const QPoint& TargetPos);
void dropWidget(QWidget* widget, const QPoint& TargetPos);
void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget);
void addDockArea(ads::CDockAreaWidget* DockAreaWidget /Transfer/, ads::DockWidgetArea area = ads::CenterDockWidgetArea);
void removeDockArea(ads::CDockAreaWidget* area /Transfer/);
void removeDockArea(ads::CDockAreaWidget* area /TransferBack/);
void saveState(QXmlStreamWriter& Stream) const;
bool restoreState(CDockingStateReader& Stream, bool Testing);
ads::CDockAreaWidget* lastAddedDockAreaWidget(ads::DockWidgetArea area) const;
bool hasTopLevelDockWidget() const;
ads::CDockWidget* topLevelDockWidget() const;
ads::CDockAreaWidget* topLevelDockArea() const;
QList<ads::CDockWidget*> dockWidgets() const;
@@ -88,6 +87,7 @@ public:
* If all dock widgets in a dock area are closed, the dock area will be closed
*/
QList<ads::CDockAreaWidget*> openedDockAreas() const;
bool hasTopLevelDockWidget() const;
/**
* Returns the number of dock areas in this container

View File

@@ -134,6 +134,8 @@ protected:
ads::CDockOverlay* containerOverlay() const;
ads::CDockOverlay* dockAreaOverlay() const;
virtual void showEvent(QShowEvent *event);
public:
enum eViewMenuInsertionOrder
{
@@ -143,7 +145,7 @@ public:
enum eConfigFlag
{
ActiveTabHasCloseButton,
ActiveTabHasCloseButton,
DockAreaHasCloseButton,
DockAreaCloseButtonClosesTab,
OpaqueSplitterResize,
@@ -152,13 +154,22 @@ public:
TabCloseButtonIsToolButton,
AllTabsHaveCloseButton,
RetainTabSizeWhenCloseButtonHidden,
OpaqueUndocking,
DragPreviewIsDynamic,
DragPreviewShowsContentPixmap,
DragPreviewHasWindowFrame,
DefaultConfig,
DefaultNonOpaqueConfig,
NonOpaqueWithWindowFrame,
OpaqueUndocking,
DragPreviewIsDynamic,
DragPreviewShowsContentPixmap,
DragPreviewHasWindowFrame,
AlwaysShowTabs,
DockAreaHasUndockButton,
DockAreaHasTabsMenuButton,
DockAreaHideDisabledButtons,
DockAreaDynamicTabsMenuButtonVisibility,
FloatingContainerHasWidgetTitle,
FloatingContainerHasWidgetIcon,
DefaultDockAreaButtons,
DefaultBaseConfig,
DefaultOpaqueConfig,
DefaultNonOpaqueConfig,
NonOpaqueWithWindowFrame,
};
typedef QFlags<ads::CDockManager::eConfigFlag> ConfigFlags;
@@ -167,6 +178,7 @@ public:
static ads::CDockManager::ConfigFlags configFlags();
static void setConfigFlags(const ads::CDockManager::ConfigFlags Flags);
static void setConfigFlag(ads::CDockManager::eConfigFlag Flag, bool On = true);
static bool testConfigFlag(eConfigFlag Flag);
static ads::CIconProvider& iconProvider();
ads::CDockAreaWidget* addDockWidget(ads::DockWidgetArea area, ads::CDockWidget* Dockwidget /Transfer/,
ads::CDockAreaWidget* DockAreaWidget /Transfer/ = 0);
@@ -180,7 +192,7 @@ public:
QMap<QString, ads::CDockWidget*> dockWidgetsMap() const;
const QList<ads::CDockContainerWidget*> dockContainers() const;
const QList<ads::CFloatingDockContainer*> floatingWidgets() const;
virtual unsigned int zOrderIndex() const;
unsigned int zOrderIndex() const;
QByteArray saveState(int version = 1) const;
bool restoreState(const QByteArray &state, int version = 1);
void addPerspective(const QString& UniquePrespectiveName);
@@ -206,6 +218,7 @@ signals:
void stateRestored();
void openingPerspective(const QString& PerspectiveName);
void perspectiveOpened(const QString& PerspectiveName);
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
void dockWidgetRemoved(ads::CDockWidget* DockWidget);

View File

@@ -24,9 +24,11 @@ public:
void setAllowedAreas(ads::DockWidgetAreas areas);
ads::DockWidgetAreas allowedAreas() const;
ads::DockWidgetArea dropAreaUnderCursor() const;
ads::DockWidgetArea visibleDropAreaUnderCursor() const;
ads::DockWidgetArea showOverlay(QWidget* target);
void hideOverlay();
void enableDropPreview(bool Enable);
bool dropPreviewEnabled() const;
QRect dropOverlayRect() const;
virtual bool event(QEvent *e);
@@ -58,6 +60,8 @@ protected:
void setIconOverlayColor(const QColor& Color);
void setIconArrowColor(const QColor& Color);
void setIconShadowColor(const QColor& Color);
virtual void showEvent(QShowEvent* e);
void setAreaWidgets(const QHash<ads::DockWidgetArea, QWidget*>& widgets);
public:
CDockOverlayCross(ads::CDockOverlay* overlay /TransferThis/);

View File

@@ -16,6 +16,9 @@ public:
CDockSplitter(Qt::Orientation orientation, QWidget *parent /TransferThis/ = 0);
virtual ~CDockSplitter();
bool hasVisibleContent() const;
QWidget* firstWidget() const;
QWidget* lastWidget() const;
};
};

View File

@@ -12,15 +12,16 @@ class CDockWidget : QFrame
%End
protected:
void setDockManager(ads::CDockManager* DockManager /Transfer/);
void setDockArea(ads::CDockAreaWidget* DockArea /Transfer/);
void setToggleViewActionChecked(bool Checked);
void saveState(QXmlStreamWriter& Stream) const;
void flagAsUnassigned();
static void emitTopLevelEventForWidget(ads::CDockWidget* TopLevelDockWidget, bool Floating);
void emitTopLevelChanged(bool Floating);
void setClosedState(bool Closed);
void toggleViewInternal(bool Open);
void setDockManager(ads::CDockManager* DockManager /Transfer/ );
void setDockArea(ads::CDockAreaWidget* DockArea /Transfer/ );
void setToggleViewActionChecked(bool Checked);
void saveState(QXmlStreamWriter& Stream) const;
void flagAsUnassigned();
static void emitTopLevelEventForWidget(ads::CDockWidget* TopLevelDockWidget, bool Floating);
void emitTopLevelChanged(bool Floating);
void setClosedState(bool Closed);
void toggleViewInternal(bool Open);
bool closeDockWidgetInternal(bool ForceClose = false);
public:
enum DockWidgetFeature
@@ -29,7 +30,9 @@ public:
DockWidgetMovable,
DockWidgetFloatable,
DockWidgetDeleteOnClose,
AllDockWidgetFeatures,
CustomCloseHandling,
DefaultDockWidgetFeatures,
AllDockWidgetFeatures,
NoDockWidgetFeatures
};
typedef QFlags<ads::CDockWidget::DockWidgetFeature> DockWidgetFeatures;
@@ -77,11 +80,14 @@ public:
QIcon icon() const;
QToolBar* toolBar() const;
QToolBar* createDefaultToolBar();
void setToolBar(QToolBar* ToolBar);
void setToolBar(QToolBar* ToolBar /Transfer/ );
void setToolBarStyle(Qt::ToolButtonStyle Style, ads::CDockWidget::eState State);
Qt::ToolButtonStyle toolBarStyle(ads::CDockWidget::eState State) const;
void setToolBarIconSize(const QSize& IconSize, ads::CDockWidget::eState State);
QSize toolBarIconSize(eState State) const;
void setTitleBarActions(QList<QAction*> actions);
virtual QList<QAction*> titleBarActions() const;
void setTabToolTip(const QString &text);
public:
@@ -91,12 +97,14 @@ public slots:
void toggleView(bool Open = true);
void setFloating();
void deleteDockWidget();
void closeDockWidget();
signals:
void viewToggled(bool Open);
void closed();
void titleChanged(const QString& Title);
void topLevelChanged(bool topLevel);
void closeRequested();
void visibilityChanged(bool visible);
void featuresChanged(ads::CDockWidget::DockWidgetFeatures features);
};

View File

@@ -23,13 +23,14 @@ public:
virtual ~CDockWidgetTab();
bool isActiveTab() const;
void setActiveTab(bool active);
ads::CDockWidget* dockWidget() const;
void setDockAreaWidget(ads::CDockAreaWidget* DockArea /Transfer/);
ads::CDockAreaWidget* dockAreaWidget() const;
ads::CDockWidget* dockWidget() const;
void setIcon(const QIcon& Icon);
const QIcon& icon() const;
QString text() const;
void setText(const QString& title);
bool isTitleElided() const;
bool isClosable() const;
virtual bool event(QEvent *e);
@@ -43,6 +44,7 @@ signals:
void closeRequested();
void closeOtherTabsRequested();
void moved(const QPoint& GlobalPos);
void elidedChanged(bool elided);
}; // class DockWidgetTab
};
// namespace ads

View File

@@ -22,7 +22,7 @@ public:
virtual ~CElidingLabel();
Qt::TextElideMode elideMode() const;
void setElideMode(Qt::TextElideMode mode);
bool isElided() const;
public:
virtual QSize minimumSizeHint() const;
@@ -33,6 +33,7 @@ public:
signals:
void clicked();
void doubleClicked();
void elidedChanged(bool elided);
};
};

View File

@@ -1,7 +1,17 @@
// NOTE: there is a separate sip/linux/FloatingDockContainer.sip as the base
// class for CFloatingDockContainer changes for Linux.
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
%If (WS_X11)
typedef QDockWidget tFloatingWidgetBase;
%End
%If (!WS_X11)
typedef QWidget tFloatingWidgetBase;
%End
namespace ads
{
@@ -20,7 +30,7 @@ public:
};
class CFloatingDockContainer : QWidget, ads::IFloatingWidget
class CFloatingDockContainer : tFloatingWidgetBase, ads::IFloatingWidget
{
%TypeHeaderCode
@@ -46,7 +56,6 @@ protected:
virtual void closeEvent(QCloseEvent *event);
virtual void hideEvent(QHideEvent *event);
virtual void showEvent(QShowEvent *event);
virtual bool eventFilter(QObject *watched, QEvent *event);
public:
CFloatingDockContainer(ads::CDockManager* DockManager /TransferThis/);

View File

@@ -12,6 +12,10 @@ class CFloatingDragPreview : QWidget, ads::IFloatingWidget
#include <FloatingDragPreview.h>
%End
protected:
virtual void moveEvent(QMoveEvent *event);
virtual void paintEvent(QPaintEvent *e);
CFloatingDragPreview(QWidget* Content /TransferThis/, QWidget* parent /TransferThis/);
public:
CFloatingDragPreview(ads::CDockWidget* Content /TransferThis/ );
@@ -21,6 +25,7 @@ public:
virtual bool eventFilter(QObject* watched, QEvent* event);
public: // implements IFloatingWidget
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
ads::eDragState DragState, QWidget* MouseEventHandler);
@@ -35,4 +40,4 @@ signals:
};
%End
%End

View File

@@ -1,13 +1,13 @@
%Module(name=PyQtAds.QtAds.ads, call_super_init=True, keyword_arguments="Optional", use_limited_api=True)
%Import QtCore/QtCoremod.sip
%DefaultSupertype sip.simplewrapper
%Platforms {Linux macOS Windows}
%Include ads_globals.sip
%Include DockWidget.sip
%Include DockAreaTabBar.sip
%Include DockAreaTitleBar.sip
%Include DockAreaWidget.sip
%Include DockComponentsFactory.sip
%Include DockContainerWidget.sip
%Include DockingStateReader.sip
%Include DockManager.sip
@@ -18,6 +18,6 @@
%Include FloatingDockContainer.sip
%Include FloatingDragPreview.sip
%Include IconProvider.sip
%If (Linux)
%If (WS_X11)
%Include linux/FloatingWidgetTitleBar.sip
%End
%End

View File

@@ -8,6 +8,13 @@ namespace ads
#include <ads_globals.h>
%End
enum eStateFileVersion
{
InitialVerison,
Version1,
CurrentVersion
};
enum DockWidgetArea
{
NoDockWidgetArea,
@@ -49,6 +56,12 @@ namespace ads
IconCount,
};
enum eBitwiseOperator
{
BitwiseAnd,
BitwiseOr
};
};
%End
%End

View File

@@ -5,7 +5,7 @@
namespace ads
{
%TypeHeaderCode
#include <FloatingWidgetTitleBar.h>
#include <linux/FloatingWidgetTitleBar.h>
%End
class CFloatingWidgetTitleBar : QWidget

View File

@@ -35,6 +35,7 @@
#include <QDebug>
#include <QBoxLayout>
#include <QApplication>
#include <QtGlobal>
#include "FloatingDockContainer.h"
#include "DockAreaWidget.h"
@@ -54,13 +55,10 @@ namespace ads
struct DockAreaTabBarPrivate
{
CDockAreaTabBar* _this;
QPoint DragStartMousePos;
CDockAreaWidget* DockArea;
IFloatingWidget* FloatingWidget = nullptr;
QWidget* TabsContainerWidget;
QBoxLayout* TabsLayout;
int CurrentIndex = -1;
eDragState DragState = DraggingInactive;
/**
* Private data constructor
@@ -74,12 +72,14 @@ struct DockAreaTabBarPrivate
void updateTabs();
/**
* Test function for current drag state
* Convenience function to access first tab
*/
bool isDraggingState(eDragState dragState) const
{
return this->DragState == dragState;
}
CDockWidgetTab* firstTab() const {return _this->tab(0);}
/**
* Convenience function to access last tab
*/
CDockWidgetTab* lastTab() const {return _this->tab(_this->count() - 1);}
};
// struct DockAreaTabBarPrivate
@@ -123,23 +123,24 @@ CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) :
d(new DockAreaTabBarPrivate(this))
{
d->DockArea = parent;
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
setFrameStyle(QFrame::NoFrame);
setWidgetResizable(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->TabsContainerWidget = new QWidget();
d->TabsContainerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->TabsContainerWidget->setObjectName("tabsContainerWidget");
setWidget(d->TabsContainerWidget);
d->TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight);
d->TabsLayout->setContentsMargins(0, 0, 0, 0);
d->TabsLayout->setSpacing(0);
d->TabsLayout->addStretch(1);
d->TabsContainerWidget->setLayout(d->TabsLayout);
setWidget(d->TabsContainerWidget);
}
//============================================================================
CDockAreaTabBar::~CDockAreaTabBar()
{
@@ -163,149 +164,6 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
}
//============================================================================
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
{
if (ev->button() == Qt::LeftButton)
{
ev->accept();
d->DragStartMousePos = ev->pos();
d->DragState = DraggingMousePressed;
return;
}
Super::mousePressEvent(ev);
}
//============================================================================
void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
{
if (ev->button() == Qt::LeftButton)
{
ADS_PRINT("CDockAreaTabBar::mouseReleaseEvent");
ev->accept();
auto CurrentDragState = d->DragState;
d->DragStartMousePos = QPoint();
d->DragState = DraggingInactive;
if (DraggingFloatingWidget == CurrentDragState)
{
d->FloatingWidget->finishDragging();
}
return;
}
Super::mouseReleaseEvent(ev);
}
//============================================================================
void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
{
Super::mouseMoveEvent(ev);
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
{
d->DragState = DraggingInactive;
return;
}
// move floating window
if (d->isDraggingState(DraggingFloatingWidget))
{
d->FloatingWidget->moveFloating();
return;
}
// If this is the last dock area in a dock container it does not make
// sense to move it to a new floating widget and leave this one
// empty
if (d->DockArea->dockContainer()->isFloating()
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
{
return;
}
// If one single dock widget in this area is not floatable then the whole
// area is not floatable
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
return;
}
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
if (DragDistance >= CDockManager::startDragDistance())
{
ADS_PRINT("CTabsScrollArea::startFloating");
startFloating(d->DragStartMousePos);
auto Overlay = d->DockArea->dockManager()->containerOverlay();
Overlay->setAllowedAreas(OuterDockAreas);
}
return;
}
//============================================================================
void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
{
// If this is the last dock area in a dock container it does not make
// sense to move it to a new floating widget and leave this one
// empty
if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1)
{
return;
}
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
return;
}
makeAreaFloating(event->pos(), DraggingInactive);
}
//============================================================================
IFloatingWidget* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset, eDragState DragState)
{
QSize Size = d->DockArea->size();
d->DragState = DragState;
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
(DraggingFloatingWidget != DragState);
CFloatingDockContainer* FloatingDockContainer = nullptr;
IFloatingWidget* FloatingWidget;
if (OpaqueUndocking)
{
FloatingWidget = FloatingDockContainer = new CFloatingDockContainer(d->DockArea);
}
else
{
auto w = new CFloatingDragPreview(d->DockArea);
connect(w, &CFloatingDragPreview::draggingCanceled, [=]()
{
d->DragState = DraggingInactive;
});
FloatingWidget = w;
}
FloatingWidget->startFloating(Offset, Size, DragState, nullptr);
if (FloatingDockContainer)
{
auto TopLevelDockWidget = FloatingDockContainer->topLevelDockWidget();
if (TopLevelDockWidget)
{
TopLevelDockWidget->emitTopLevelChanged(true);
}
}
return FloatingWidget;
}
//============================================================================
void CDockAreaTabBar::startFloating(const QPoint& Offset)
{
d->FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
}
//============================================================================
void CDockAreaTabBar::setCurrentIndex(int index)
{
@@ -323,6 +181,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
emit currentChanging(index);
d->CurrentIndex = index;
d->updateTabs();
updateGeometry();
emit currentChanged(index);
}
@@ -343,12 +202,15 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
connect(Tab, SIGNAL(closeRequested()), this, SLOT(onTabCloseRequested()));
connect(Tab, SIGNAL(closeOtherTabsRequested()), this, SLOT(onCloseOtherTabsRequested()));
connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&)));
connect(Tab, SIGNAL(elidedChanged(bool)), this, SIGNAL(elidedChanged(bool)));
Tab->installEventFilter(this);
emit tabInserted(Index);
if (Index <= d->CurrentIndex)
if (Index <= d->CurrentIndex || d->CurrentIndex == -1)
{
setCurrentIndex(d->CurrentIndex + 1);
}
updateGeometry();
}
@@ -411,6 +273,8 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
{
d->updateTabs();
}
updateGeometry();
}
@@ -513,6 +377,8 @@ void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
int fromIndex = d->TabsLayout->indexOf(MovingTab);
auto MousePos = mapFromGlobal(GlobalPos);
MousePos.rx() = qMax(d->firstTab()->geometry().left(), MousePos.x());
MousePos.rx() = qMin(d->lastTab()->geometry().right(), MousePos.x());
int toIndex = -1;
// Find tab under mouse
for (int i = 0; i < count(); ++i)
@@ -528,41 +394,25 @@ void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
if (toIndex == fromIndex)
{
toIndex = -1;
continue;
}
if (toIndex < 0)
{
toIndex = 0;
}
break;
}
// Now check if the mouse is behind the last tab
if (toIndex < 0)
{
if (MousePos.x() > tab(count() - 1)->geometry().right())
{
ADS_PRINT("after all tabs");
toIndex = count() - 1;
}
else
{
toIndex = fromIndex;
}
}
d->TabsLayout->removeWidget(MovingTab);
d->TabsLayout->insertWidget(toIndex, MovingTab);
if (toIndex >= 0)
if (toIndex > -1)
{
d->TabsLayout->removeWidget(MovingTab);
d->TabsLayout->insertWidget(toIndex, MovingTab);
ADS_PRINT("tabMoved from " << fromIndex << " to " << toIndex);
emit tabMoved(fromIndex, toIndex);
setCurrentIndex(toIndex);
}
else
{
// Ensure that the moved tab is reset to its start position
d->TabsLayout->update();
}
}
//===========================================================================
void CDockAreaTabBar::closeTab(int Index)
{
@@ -576,7 +426,6 @@ void CDockAreaTabBar::closeTab(int Index)
{
return;
}
//Tab->hide();
emit tabCloseRequested(Index);
}
@@ -594,9 +443,15 @@ bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event)
switch (event->type())
{
case QEvent::Hide:
emit tabClosed(d->TabsLayout->indexOf(Tab)); break;
emit tabClosed(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;
case QEvent::Show:
emit tabOpened(d->TabsLayout->indexOf(Tab)); break;
emit tabOpened(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;
default:
break;
}
@@ -621,7 +476,7 @@ bool CDockAreaTabBar::isTabOpen(int Index) const
QSize CDockAreaTabBar::minimumSizeHint() const
{
QSize Size = sizeHint();
Size.setWidth(Super::minimumSizeHint().width());// this defines the minimum width of a dock area
Size.setWidth(10);
return Size;
}
@@ -629,19 +484,11 @@ QSize CDockAreaTabBar::minimumSizeHint() const
//===========================================================================
QSize CDockAreaTabBar::sizeHint() const
{
QSize Size = Super::sizeHint();
Size.setHeight(d->TabsContainerWidget->sizeHint().height());
return Size;
}
//===========================================================================
eDragState CDockAreaTabBar::dragState() const
{
return d->DragState;
return d->TabsContainerWidget->sizeHint();
}
} // namespace ads
//---------------------------------------------------------------------------
// EOF DockAreaTabBar.cpp

View File

@@ -67,42 +67,6 @@ private slots:
protected:
virtual void wheelEvent(QWheelEvent* Event) override;
/**
* Stores mouse position to detect dragging
*/
virtual void mousePressEvent(QMouseEvent* ev) override;
/**
* Stores mouse position to detect dragging
*/
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
/**
* Starts floating the complete docking area including all dock widgets,
* if it is not the last dock area in a floating widget
*/
virtual void mouseMoveEvent(QMouseEvent* ev) override;
/**
* Double clicking the title bar also starts floating of the complete area
*/
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
/**
* Starts floating
*/
void startFloating(const QPoint& Offset);
/**
* Makes the dock area floating
*/
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
/**
* Returns the current drag state
*/
eDragState dragState() const;
public:
using Super = QScrollArea;
@@ -239,6 +203,11 @@ signals:
* This signal is emitted if a tab has been inserted
*/
void tabInserted(int index);
/**
* This signal is emitted when a tab title elide state has been changed
*/
void elidedChanged(bool elided);
}; // class CDockAreaTabBar
} // namespace ads
//-----------------------------------------------------------------------------

View File

@@ -37,9 +37,11 @@
#include <QScrollArea>
#include <QMouseEvent>
#include <QDebug>
#include <QPointer>
#include "ads_globals.h"
#include "FloatingDockContainer.h"
#include "FloatingDragPreview.h"
#include "DockAreaWidget.h"
#include "DockOverlay.h"
#include "DockManager.h"
@@ -47,26 +49,35 @@
#include "DockWidgetTab.h"
#include "DockAreaTabBar.h"
#include "IconProvider.h"
#include "DockComponentsFactory.h"
#include <iostream>
namespace ads
{
using tTileBarButton = QToolButton;
using tTitleBarButton = QToolButton;
/**
* Private data class of CDockAreaTitleBar class (pimpl)
*/
struct DockAreaTitleBarPrivate
{
CDockAreaTitleBar* _this;
tTileBarButton* TabsMenuButton;
tTileBarButton* UndockButton;
tTileBarButton* CloseButton;
QBoxLayout* TopLayout;
QPointer<tTitleBarButton> TabsMenuButton;
QPointer<tTitleBarButton> UndockButton;
QPointer<tTitleBarButton> CloseButton;
QBoxLayout* Layout;
CDockAreaWidget* DockArea;
CDockAreaTabBar* TabBar;
bool MenuOutdated = true;
QMenu* TabsMenu;
QList<tTitleBarButton*> DockWidgetActionsButtons;
QPoint DragStartMousePos;
eDragState DragState = DraggingInactive;
IFloatingWidget* FloatingWidget = nullptr;
/**
* Private data constructor
@@ -94,41 +105,110 @@ struct DockAreaTitleBarPrivate
/**
* Returns true if the given config flag is set
*/
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
static bool testConfigFlag(CDockManager::eConfigFlag Flag)
{
return CDockManager::configFlags().testFlag(Flag);
}
/**
* Helper function to set title bar button icons depending on operating
* system and to avoid duplicated code. On windows the standard icons
* are blurry since Qt 5.11 so we need to do some additional steps.
* If the global IconPovider of the dockmanager provides a custom
* Icon for the given CustomIconId, the this icon will be used.
*/
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap,
ads::eIcon CustomIconId)
{
// First we try to use custom icons if available
QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId);
if (!Icon.isNull())
{
Button->setIcon(Icon);
return;
}
/**
* Test function for current drag state
*/
bool isDraggingState(eDragState dragState) const
{
return this->DragState == dragState;
}
#ifdef Q_OS_LINUX
Button->setIcon(_this->style()->standardIcon(StandarPixmap));
#else
QPixmap normalPixmap = _this->style()->standardPixmap(StandarPixmap, 0, Button);
Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
Icon.addPixmap(normalPixmap, QIcon::Normal);
Button->setIcon(Icon);
#endif
}
/**
* Starts floating
*/
void startFloating(const QPoint& Offset);
/**
* Makes the dock area floating
*/
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
};// struct DockAreaTitleBarPrivate
/**
* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour
* according to various config flags such as:
* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible
* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled
*/
class CTitleBarButton : public tTitleBarButton
{
Q_OBJECT
bool Visible = true;
bool HideWhenDisabled = false;
public:
using Super = tTitleBarButton;
CTitleBarButton(bool visible = true, QWidget* parent = nullptr)
: tTitleBarButton(parent),
Visible(visible),
HideWhenDisabled(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
{}
/**
* Adjust this visibility change request with our internal settings:
*/
virtual void setVisible(bool visible) override
{
// 'visible' can stay 'true' if and only if this button is configured to generaly visible:
visible = visible && this->Visible;
// 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled:
if(visible && HideWhenDisabled)
{
visible = isEnabled();
}
Super::setVisible(visible);
}
protected:
/**
* Handle EnabledChanged signal to set button invisible if the configured
*/
bool event(QEvent *ev) override
{
if(QEvent::EnabledChange == ev->type() && HideWhenDisabled)
{
// force setVisible() call
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled()));
}
return Super::event(ev);
}
};
/**
* This spacer widget is here because of the following problem.
* The dock area title bar handles mouse dragging and moving the floating widget.
* The problem is, that if the title bar becomes invisible, i.e. if the dock
* area contains only one single dock widget and the dock area is moved
* into a floating widget, then mouse events are not handled anymore and dragging
* of the floating widget stops.
*/
class CSpacerWidget : public QWidget
{
Q_OBJECT
public:
using Super = QWidget;
CSpacerWidget(QWidget* Parent = 0)
: Super(Parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setStyleSheet("border: none; background: none;");
}
virtual QSize sizeHint() const override {return QSize(0, 0);}
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
};
//============================================================================
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
@@ -142,61 +222,51 @@ DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
void DockAreaTitleBarPrivate::createButtons()
{
QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
// Tabs menu button
TabsMenuButton = new tTileBarButton();
// Tabs menu button
TabsMenuButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasTabsMenuButton));
TabsMenuButton->setObjectName("tabsMenuButton");
TabsMenuButton->setAutoRaise(true);
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon);
internal::setButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon);
QMenu* TabsMenu = new QMenu(TabsMenuButton);
#ifndef QT_NO_TOOLTIP
TabsMenu->setToolTipsVisible(true);
#endif
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
TabsMenuButton->setMenu(TabsMenu);
#ifndef QT_NO_TOOLTIP
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
#endif
internal::setToolTip(TabsMenuButton, QObject::tr("List All Tabs"));
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
TopLayout->addWidget(TabsMenuButton, 0);
Layout->addWidget(TabsMenuButton, 0);
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
SLOT(onTabsMenuActionTriggered(QAction*)));
// Undock button
UndockButton = new tTileBarButton();
UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton));
UndockButton->setObjectName("undockButton");
UndockButton->setAutoRaise(true);
#ifndef QT_NO_TOOLTIP
UndockButton->setToolTip(QObject::tr("Detach Group"));
#endif
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
UndockButton->setSizePolicy(ButtonSizePolicy);
TopLayout->addWidget(UndockButton, 0);
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
UndockButton->setSizePolicy(ButtonSizePolicy);
Layout->addWidget(UndockButton, 0);
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
// Close button
CloseButton = new tTileBarButton();
// Close button
CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton));
CloseButton->setObjectName("closeButton");
CloseButton->setAutoRaise(true);
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
#ifndef QT_NO_TOOLTIP
internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
{
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
internal::setToolTip(CloseButton, QObject::tr("Close Active Tab"));
}
else
{
CloseButton->setToolTip(QObject::tr("Close Group"));
internal::setToolTip(CloseButton, QObject::tr("Close Group"));
}
#endif
CloseButton->setSizePolicy(ButtonSizePolicy);
CloseButton->setIconSize(QSize(16, 16));
if (testConfigFlag(CDockManager::DockAreaHasCloseButton))
{
TopLayout->addWidget(CloseButton, 0);
}
Layout->addWidget(CloseButton, 0);
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
}
@@ -204,8 +274,9 @@ void DockAreaTitleBarPrivate::createButtons()
//============================================================================
void DockAreaTitleBarPrivate::createTabBar()
{
TabBar = new CDockAreaTabBar(DockArea);
TopLayout->addWidget(TabBar);
TabBar = componentsFactory()->createDockAreaTabBar(DockArea);
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
Layout->addWidget(TabBar);
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
@@ -213,10 +284,51 @@ void DockAreaTitleBarPrivate::createTabBar()
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
_this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated()));
}
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(showContextMenu(const QPoint&)));
//============================================================================
IFloatingWidget* DockAreaTitleBarPrivate::makeAreaFloating(const QPoint& Offset, eDragState DragState)
{
QSize Size = DockArea->size();
this->DragState = DragState;
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
(DraggingFloatingWidget != DragState);
CFloatingDockContainer* FloatingDockContainer = nullptr;
IFloatingWidget* FloatingWidget;
if (OpaqueUndocking)
{
FloatingWidget = FloatingDockContainer = new CFloatingDockContainer(DockArea);
}
else
{
auto w = new CFloatingDragPreview(DockArea);
QObject::connect(w, &CFloatingDragPreview::draggingCanceled, [=]()
{
this->DragState = DraggingInactive;
});
FloatingWidget = w;
}
FloatingWidget->startFloating(Offset, Size, DragState, nullptr);
if (FloatingDockContainer)
{
auto TopLevelDockWidget = FloatingDockContainer->topLevelDockWidget();
if (TopLevelDockWidget)
{
TopLevelDockWidget->emitTopLevelChanged(true);
}
}
return FloatingWidget;
}
//============================================================================
void DockAreaTitleBarPrivate::startFloating(const QPoint& Offset)
{
FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
}
@@ -228,21 +340,35 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
d->DockArea = parent;
setObjectName("dockAreaTitleBar");
d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
d->TopLayout->setContentsMargins(0, 0, 0, 0);
d->TopLayout->setSpacing(0);
setLayout(d->TopLayout);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
d->Layout = new QBoxLayout(QBoxLayout::LeftToRight);
d->Layout->setContentsMargins(0, 0, 0, 0);
d->Layout->setSpacing(0);
setLayout(d->Layout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
d->createTabBar();
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons();
}
//============================================================================
CDockAreaTitleBar::~CDockAreaTitleBar()
{
if (!d->CloseButton.isNull())
{
delete d->CloseButton;
}
if (!d->TabsMenuButton.isNull())
{
delete d->TabsMenuButton;
}
if (!d->UndockButton.isNull())
{
delete d->UndockButton;
}
delete d;
}
@@ -253,14 +379,31 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
return d->TabBar;
}
//============================================================================
void CDockAreaTitleBar::markTabsMenuOutdated()
{
if(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility))
{
bool hasElidedTabTitle = false;
for (int i = 0; i < d->TabBar->count(); ++i)
{
if (!d->TabBar->isTabOpen(i))
{
continue;
}
CDockWidgetTab* Tab = d->TabBar->tab(i);
if(Tab->isTitleElided())
{
hasElidedTabTitle = true;
break;
}
}
bool visible = (hasElidedTabTitle && (d->TabBar->count() > 1));
QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible));
}
d->MenuOutdated = true;
}
//============================================================================
void CDockAreaTitleBar::onTabsMenuAboutToShow()
{
@@ -279,9 +422,7 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
}
auto Tab = d->TabBar->tab(i);
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
#ifndef QT_NO_TOOLTIP
Action->setToolTip(Tab->toolTip());
#endif
internal::setToolTip(Action, Tab->toolTip());
Action->setData(i);
}
@@ -309,7 +450,7 @@ void CDockAreaTitleBar::onUndockButtonClicked()
{
if (d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
d->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
}
}
@@ -323,6 +464,40 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
}
//============================================================================
void CDockAreaTitleBar::updateDockWidgetActionsButtons()
{
CDockWidget* DockWidget = d->TabBar->currentTab()->dockWidget();
if (!d->DockWidgetActionsButtons.isEmpty())
{
for (auto Button : d->DockWidgetActionsButtons)
{
d->Layout->removeWidget(Button);
delete Button;
}
d->DockWidgetActionsButtons.clear();
}
auto Actions = DockWidget->titleBarActions();
if (Actions.isEmpty())
{
return;
}
int InsertIndex = indexOf(d->TabsMenuButton);
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->Layout->insertWidget(InsertIndex++, Button, 0);
d->DockWidgetActionsButtons.append(Button);
}
}
//============================================================================
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
{
@@ -336,6 +511,8 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
}
updateDockWidgetActionsButtons();
}
@@ -362,9 +539,113 @@ void CDockAreaTitleBar::setVisible(bool Visible)
//============================================================================
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
{
if (d->TabBar->dragState() == DraggingFloatingWidget)
if (ev->button() == Qt::LeftButton)
{
ev->accept();
d->DragStartMousePos = ev->pos();
d->DragState = DraggingMousePressed;
return;
}
Super::mousePressEvent(ev);
}
//============================================================================
void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev)
{
if (ev->button() == Qt::LeftButton)
{
ADS_PRINT("CDockAreaTitleBar::mouseReleaseEvent");
ev->accept();
auto CurrentDragState = d->DragState;
d->DragStartMousePos = QPoint();
d->DragState = DraggingInactive;
if (DraggingFloatingWidget == CurrentDragState)
{
d->FloatingWidget->finishDragging();
}
return;
}
Super::mouseReleaseEvent(ev);
}
//============================================================================
void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev)
{
Super::mouseMoveEvent(ev);
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
{
d->DragState = DraggingInactive;
return;
}
// move floating window
if (d->isDraggingState(DraggingFloatingWidget))
{
d->FloatingWidget->moveFloating();
return;
}
// If this is the last dock area in a dock container it does not make
// sense to move it to a new floating widget and leave this one
// empty
if (d->DockArea->dockContainer()->isFloating()
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
{
return;
}
// If one single dock widget in this area is not floatable then the whole
// area is not floatable
// If we do non opaque undocking, then we can create the floating drag
// preview if the dock widget is movable
auto Features = d->DockArea->features();
if (!Features.testFlag(CDockWidget::DockWidgetFloatable)
&& !(Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)))
{
return;
}
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
if (DragDistance >= CDockManager::startDragDistance())
{
ADS_PRINT("CTabsScrollArea::startFloating");
d->startFloating(d->DragStartMousePos);
auto Overlay = d->DockArea->dockManager()->containerOverlay();
Overlay->setAllowedAreas(OuterDockAreas);
}
return;
}
//============================================================================
void CDockAreaTitleBar::mouseDoubleClickEvent(QMouseEvent *event)
{
// If this is the last dock area in a dock container it does not make
// sense to move it to a new floating widget and leave this one
// empty
if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1)
{
return;
}
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
return;
}
d->makeAreaFloating(event->pos(), DraggingInactive);
}
//============================================================================
void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
{
ev->accept();
if (d->isDraggingState(DraggingFloatingWidget))
{
return;
}
@@ -376,11 +657,27 @@ void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
Menu.exec(mapToGlobal(pos));
Menu.exec(ev->globalPos());
}
//============================================================================
void CDockAreaTitleBar::insertWidget(int index, QWidget *widget)
{
d->Layout->insertWidget(index, widget);
}
//============================================================================
int CDockAreaTitleBar::indexOf(QWidget *widget) const
{
return d->Layout->indexOf(widget);
}
} // namespace ads
#include "DockAreaTitleBar.moc"
//---------------------------------------------------------------------------
// EOF DockAreaTitleBar.cpp

View File

@@ -60,7 +60,33 @@ private slots:
void onUndockButtonClicked();
void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index);
void showContextMenu(const QPoint& pos);
protected:
/**
* Stores mouse position to detect dragging
*/
virtual void mousePressEvent(QMouseEvent* ev) override;
/**
* Stores mouse position to detect dragging
*/
virtual void mouseReleaseEvent(QMouseEvent* ev) override;
/**
* Starts floating the complete docking area including all dock widgets,
* if it is not the last dock area in a floating widget
*/
virtual void mouseMoveEvent(QMouseEvent* ev) override;
/**
* Double clicking the title bar also starts floating of the complete area
*/
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
/**
* Show context menu
*/
virtual void contextMenuEvent(QContextMenuEvent *event);
public slots:
/**
@@ -72,6 +98,7 @@ public slots:
public:
using Super = QFrame;
/**
* Default Constructor
*/
@@ -92,12 +119,34 @@ public:
*/
QAbstractButton* button(TitleBarButton which) const;
/**
* Updates the visibility of the dock widget actions in the title bar
*/
void updateDockWidgetActionsButtons();
/**
* Marks the tabs menu outdated before it calls its base class
* implementation
*/
virtual void setVisible(bool Visible) override;
/**
* Inserts a custom widget at position index into this title bar.
* If index is negative, the widget is added at the end.
* You can use this function to insert custom widgets into the title bar.
*/
void insertWidget(int index, QWidget *widget);
/**
* Searches for widget widget in this title bar.
* You can use this function, to get the position of the default
* widget in the tile bar.
* \code
* int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar());
* int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose));
* \endcode
*/
int indexOf(QWidget *widget) const;
signals:
/**

View File

@@ -28,9 +28,10 @@
//============================================================================
// INCLUDES
//============================================================================
#include "DockWidgetTab.h"
#include "DockAreaWidget.h"
#include <iostream>
#include <QStackedLayout>
#include <QScrollBar>
#include <QScrollArea>
@@ -53,8 +54,8 @@
#include "DockAreaTabBar.h"
#include "DockSplitter.h"
#include "DockAreaTitleBar.h"
#include <iostream>
#include "DockComponentsFactory.h"
#include "DockWidgetTab.h"
namespace ads
@@ -245,6 +246,7 @@ struct DockAreaWidgetPrivate
CDockAreaTitleBar* TitleBar = nullptr;
CDockManager* DockManager = nullptr;
bool UpdateTitleBarButtons = false;
DockWidgetAreas AllowedAreas = AllDockAreas;
/**
* Private data constructor
@@ -261,7 +263,7 @@ struct DockAreaWidgetPrivate
*/
CDockWidget* dockWidgetAt(int index)
{
return dynamic_cast<CDockWidget*>(ContentsLayout->widget(index));
return qobject_cast<CDockWidget*>(ContentsLayout->widget(index));
}
/**
@@ -316,7 +318,7 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
//============================================================================
void DockAreaWidgetPrivate::createTitleBar()
{
TitleBar = new CDockAreaTitleBar(_this);
TitleBar = componentsFactory()->createDockAreaTitleBar(_this);
Layout->addWidget(TitleBar);
QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested);
QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex);
@@ -337,6 +339,7 @@ void DockAreaWidgetPrivate::updateTitleBarButtonStates()
_this->features().testFlag(CDockWidget::DockWidgetClosable));
TitleBar->button(TitleBarButtonUndock)->setEnabled(
_this->features().testFlag(CDockWidget::DockWidgetFloatable));
TitleBar->updateDockWidgetActionsButtons();
UpdateTitleBarButtons = false;
}
@@ -494,7 +497,6 @@ void CDockAreaWidget::onTabCloseRequested(int Index)
auto* DockWidget = dockWidget(Index);
if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose))
{
//DockWidget->deleteDockWidget();
DockWidget->closeDockWidgetInternal();
}
else
@@ -702,6 +704,11 @@ void CDockAreaWidget::updateTitleBarVisibility()
return;
}
if (CDockManager::configFlags().testFlag(CDockManager::AlwaysShowTabs))
{
return;
}
if (d->TitleBar)
{
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
@@ -807,6 +814,15 @@ void CDockAreaWidget::setVisible(bool Visible)
}
}
void CDockAreaWidget::setAllowedAreas(DockWidgetAreas areas)
{
d->AllowedAreas = areas;
}
DockWidgetAreas CDockAreaWidget::allowedAreas() const
{
return d->AllowedAreas;
}
//============================================================================
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
@@ -840,6 +856,13 @@ void CDockAreaWidget::closeOtherAreas()
{
dockContainer()->closeOtherAreas(this);
}
//============================================================================
CDockAreaTitleBar* CDockAreaWidget::titleBar() const
{
return d->TitleBar;
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -44,6 +44,7 @@ struct DockAreaWidgetPrivate;
class CDockManager;
class CDockContainerWidget;
class DockContainerWidgetPrivate;
class CDockAreaTitleBar;
/**
@@ -254,6 +255,21 @@ public:
*/
virtual void setVisible(bool Visible) override;
/**
* Configures the areas of this particular dock area that are allowed for docking
*/
void setAllowedAreas(DockWidgetAreas areas);
/**
* Returns flags with all allowed drop areas of this particular dock area
*/
DockWidgetAreas allowedAreas() const;
/**
* Returns the title bar of this dock area
*/
CDockAreaTitleBar* titleBar() const;
public slots:
/**
* This activates the tab for the given tab index.

View File

@@ -0,0 +1,69 @@
//============================================================================
/// \file DockComponentsFactory.cpp
/// \author Uwe Kindler
/// \date 10.02.2020
/// \brief Implementation of DockComponentsFactory
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
#include <DockComponentsFactory.h>
#include <memory>
#include "DockWidgetTab.h"
#include "DockAreaTabBar.h"
#include "DockAreaTitleBar.h"
#include "DockWidget.h"
#include "DockAreaWidget.h"
namespace ads
{
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
//============================================================================
CDockWidgetTab* CDockComponentsFactory::createDockWidgetTab(CDockWidget* DockWidget) const
{
return new CDockWidgetTab(DockWidget);
}
//============================================================================
CDockAreaTabBar* CDockComponentsFactory::createDockAreaTabBar(CDockAreaWidget* DockArea) const
{
return new CDockAreaTabBar(DockArea);
}
//============================================================================
CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidget* DockArea) const
{
return new CDockAreaTitleBar(DockArea);
}
//============================================================================
const CDockComponentsFactory* CDockComponentsFactory::factory()
{
return DefaultFactory.get();
}
//============================================================================
void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory)
{
DefaultFactory.reset(Factory);
}
//============================================================================
void CDockComponentsFactory::resetDefaultFactory()
{
DefaultFactory.reset(new CDockComponentsFactory());
}
} // namespace ads
//---------------------------------------------------------------------------
// EOF DockComponentsFactory.cpp

View File

@@ -0,0 +1,90 @@
#ifndef DockComponentsFactoryH
#define DockComponentsFactoryH
//============================================================================
/// \file DockComponentsFactory.h
/// \author Uwe Kindler
/// \date 10.02.2020
/// \brief Declaration of DockComponentsFactory
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
#include "ads_globals.h"
namespace ads
{
class CDockWidgetTab;
class CDockAreaTitleBar;
class CDockAreaTabBar;
class CDockAreaWidget;
class CDockWidget;
/**
* Factory for creation of certain GUI elements for the docking framework.
* A default unique instance provided by CDockComponentsFactory is used for
* creation of all supported components. To inject your custom components,
* you can create your own derived dock components factory and register
* it via setDefaultFactory() function.
* \code
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
* \endcode
*/
class ADS_EXPORT CDockComponentsFactory
{
public:
/**
* Force virtual destructor
*/
virtual ~CDockComponentsFactory() {}
/**
* This default implementation just creates a dock widget tab with
* new CDockWidgetTab(DockWIdget).
*/
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget) const;
/**
* This default implementation just creates a dock area tab bar with
* new CDockAreaTabBar(DockArea).
*/
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea) const;
/**
* This default implementation just creates a dock area title bar with
* new CDockAreaTitleBar(DockArea).
*/
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
/**
* Returns the default components factory
*/
static const CDockComponentsFactory* factory();
/**
* Sets a new default factory for creation of GUI elements.
* This function takes ownership of the given Factory.
*/
static void setFactory(CDockComponentsFactory* Factory);
/**
* Resets the current factory to the
*/
static void resetDefaultFactory();
};
/**
* Convenience function to ease factory instance access
*/
inline const CDockComponentsFactory* componentsFactory()
{
return CDockComponentsFactory::factory();
}
} // namespace ads
//---------------------------------------------------------------------------
#endif // DockComponentsFactoryH

View File

@@ -334,7 +334,7 @@ eDropMode DockContainerWidgetPrivate::getDropMode(const QPoint& TargetPos)
if (DockArea)
{
auto dropOverlay = DockManager->dockAreaOverlay();
dropOverlay->setAllowedAreas(AllDockAreas);
dropOverlay->setAllowedAreas(DockArea->allowedAreas());
dropArea = dropOverlay->showOverlay(DockArea);
if (ContainerDropArea != InvalidDockWidgetArea &&
ContainerDropArea != dropArea)
@@ -679,6 +679,23 @@ void DockContainerWidgetPrivate::moveToContainer(QWidget* Widget, DockWidgetArea
}
else
{
// We check, if we insert the dropped widget into the same place that
// it already has and do nothing, if it is the same place. It would
// also work without this check, but it looks nicer with the check
// because there will be no layout updates
auto Splitter = internal::findParent<CDockSplitter*>(DroppedDockArea);
auto InsertParam = internal::dockAreaInsertParameters(area);
if (Splitter == RootSplitter && InsertParam.orientation() == Splitter->orientation())
{
if (InsertParam.append() && Splitter->lastWidget() == DroppedDockArea)
{
return;
}
else if (!InsertParam.append() && Splitter->firstWidget() == DroppedDockArea)
{
return;
}
}
DroppedDockArea->dockContainer()->removeDockArea(DroppedDockArea);
NewDockArea = DroppedDockArea;
}
@@ -736,7 +753,7 @@ void DockContainerWidgetPrivate::appendDockAreas(const QList<CDockAreaWidget*> N
//============================================================================
void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidget* Widget)
{
QSplitter* Splitter = dynamic_cast<QSplitter*>(Widget);
QSplitter* Splitter = qobject_cast<QSplitter*>(Widget);
if (Splitter)
{
s.writeStartElement("Splitter");
@@ -759,7 +776,7 @@ void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidge
}
else
{
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(Widget);
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Widget);
if (DockArea)
{
DockArea->saveState(s);
@@ -1046,7 +1063,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
{
#if defined(QT_DEBUG)
QSplitter* Splitter = dynamic_cast<QSplitter*>(widget);
QSplitter* Splitter = qobject_cast<QSplitter*>(widget);
QByteArray buf;
buf.fill(' ', level * 4);
if (Splitter)
@@ -1069,7 +1086,7 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
}
else
{
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(widget);
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(widget);
if (!DockArea)
{
return;
@@ -1285,7 +1302,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
}
QWidget* widget = Splitter->widget(0);
QSplitter* ChildSplitter = dynamic_cast<QSplitter*>(widget);
QSplitter* ChildSplitter = qobject_cast<QSplitter*>(widget);
// If the one and only content widget of the splitter is not a splitter
// then we are finished
if (!ChildSplitter)
@@ -1392,7 +1409,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
if (DockArea)
{
auto dropOverlay = d->DockManager->dockAreaOverlay();
dropOverlay->setAllowedAreas(AllDockAreas);
dropOverlay->setAllowedAreas(DockArea->allowedAreas());
dropArea = dropOverlay->showOverlay(DockArea);
if (ContainerDropArea != InvalidDockWidgetArea &&
ContainerDropArea != dropArea)
@@ -1436,41 +1453,16 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
//============================================================================
void CDockContainerWidget::dropWidget(QWidget* Widget, const QPoint& TargetPos)
void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget)
{
ADS_PRINT("CDockContainerWidget::dropFloatingWidget");
CDockWidget* SingleDockWidget = topLevelDockWidget();
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
auto dropArea = InvalidDockWidgetArea;
auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
if (DockArea)
if (TargetAreaWidget)
{
auto dropOverlay = d->DockManager->dockAreaOverlay();
dropOverlay->setAllowedAreas(AllDockAreas);
dropArea = dropOverlay->showOverlay(DockArea);
if (ContainerDropArea != InvalidDockWidgetArea &&
ContainerDropArea != dropArea)
{
dropArea = InvalidDockWidgetArea;
}
if (dropArea != InvalidDockWidgetArea)
{
ADS_PRINT("Dock Area Drop Content: " << dropArea);
d->moveToNewSection(Widget, DockArea, dropArea);
}
d->moveToNewSection(Widget, TargetAreaWidget, DropArea);
}
// mouse is over container
if (InvalidDockWidgetArea == dropArea)
else
{
dropArea = ContainerDropArea;
ADS_PRINT("Container Drop Content: " << dropArea);
if (dropArea != InvalidDockWidgetArea)
{
d->moveToContainer(Widget, dropArea);
}
d->moveToContainer(Widget, DropArea);
}
// If there was a top level widget before the drop, then it is not top
@@ -1573,7 +1565,7 @@ bool CDockContainerWidget::restoreState(CDockingStateReader& s, bool Testing)
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
QSplitter* OldRoot = d->RootSplitter;
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
d->RootSplitter = qobject_cast<QSplitter*>(NewRootSplitter);
OldRoot->deleteLater();
return true;

View File

@@ -96,9 +96,13 @@ protected:
void dropFloatingWidget(CFloatingDockContainer* FloatingWidget, const QPoint& TargetPos);
/**
* Drop a dock area or a dock widget given in widget parameter
* Drop a dock area or a dock widget given in widget parameter.
* If the TargetAreaWidget is a nullptr, then the DropArea indicates
* the drop area for the container. If the given TargetAreaWidget is not
* a nullptr, then the DropArea indicates the drop area in the given
* TargetAreaWidget
*/
void dropWidget(QWidget* Widget, const QPoint& TargetPos);
void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget);
/**
* Adds the given dock area to this container widget
@@ -130,14 +134,6 @@ protected:
*/
CDockAreaWidget* lastAddedDockAreaWidget(DockWidgetArea area) const;
/**
* This function returns true if this dock area has only one single
* visible dock widget.
* A top level widget is a real floating widget. Only the isFloating()
* function of top level widgets may returns true.
*/
bool hasTopLevelDockWidget() const;
/**
* If hasSingleVisibleDockWidget() returns true, this function returns the
* one and only visible dock widget. Otherwise it returns a nullptr.
@@ -214,6 +210,14 @@ public:
*/
QList<CDockAreaWidget*> openedDockAreas() const;
/**
* This function returns true if this dock area has only one single
* visible dock widget.
* A top level widget is a real floating widget. Only the isFloating()
* function of top level widgets may returns true.
*/
bool hasTopLevelDockWidget() const;
/**
* Returns the number of dock areas in this container
*/

View File

@@ -58,7 +58,7 @@
namespace ads
{
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultConfig;
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig;
/**
* Private data class of CDockManager class (pimpl)
@@ -411,7 +411,7 @@ CDockManager::CDockManager(QWidget *parent) :
d(new DockManagerPrivate(this))
{
createRootSplitter();
QMainWindow* MainWindow = dynamic_cast<QMainWindow*>(parent);
QMainWindow* MainWindow = qobject_cast<QMainWindow*>(parent);
if (MainWindow)
{
MainWindow->setCentralWidget(this);
@@ -440,6 +440,7 @@ CDockManager::~CDockManager()
void CDockManager::registerFloatingWidget(CFloatingDockContainer* FloatingWidget)
{
d->FloatingWidgets.append(FloatingWidget);
emit floatingWidgetCreated(FloatingWidget);
ADS_PRINT("d->FloatingWidgets.count() " << d->FloatingWidgets.count());
}
@@ -777,6 +778,10 @@ QAction* CDockManager::addToggleViewActionToMenu(QAction* ToggleViewAction,
d->addActionToMenu(GroupMenu->menuAction(), d->ViewMenu, AlphabeticallySorted);
d->ViewMenuGroups.insert(Group, GroupMenu);
}
else if (GroupMenu->icon().isNull() && !GroupIcon.isNull())
{
GroupMenu->setIcon(GroupIcon);
}
d->addActionToMenu(ToggleViewAction, GroupMenu, AlphabeticallySorted);
return GroupMenu->menuAction();
@@ -837,6 +842,12 @@ void CDockManager::setConfigFlag(eConfigFlag Flag, bool On)
internal::setFlag(StaticConfigFlags, Flag, On);
}
//===========================================================================
bool CDockManager::testConfigFlag(eConfigFlag Flag)
{
return configFlags().testFlag(Flag);
}
//===========================================================================
CIconProvider& CDockManager::iconProvider()

View File

@@ -59,6 +59,7 @@ class CDockWidgetTab;
struct DockWidgetTabPrivate;
struct DockAreaWidgetPrivate;
class CIconProvider;
class CDockComponentsFactory;
/**
* The central dock manager that maintains the complete docking system.
@@ -88,6 +89,7 @@ private:
friend struct DockWidgetTabPrivate;
friend class CFloatingDragPreview;
friend struct FloatingDragPreviewPrivate;
friend class CDockAreaTitleBar;
protected:
/**
@@ -140,12 +142,13 @@ public:
/**
* These global configuration flags configure some global dock manager
* settings.
* Set the dock manager flags, before you create the dock manager instance.
*/
enum eConfigFlag
{
ActiveTabHasCloseButton = 0x0001, //!< If this flag is set, the active tab in a tab area has a close button
DockAreaHasCloseButton = 0x0002, //!< If the flag is set each dock area has a close button
DockAreaCloseButtonClosesTab = 0x0004,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
DockAreaCloseButtonClosesTab = 0x0004,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete dock area
OpaqueSplitterResize = 0x0008, //!< See QSplitter::setOpaqueResize() documentation
XmlAutoFormattingEnabled = 0x0010,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
XmlCompressionEnabled = 0x0020,//!< If enabled, the XML output will be compressed and is not human readable anymore
@@ -156,19 +159,32 @@ public:
DragPreviewIsDynamic = 0x0400,///< If opaque undocking is disabled, this flag defines the behavior of the drag preview window, if this flag is enabled, the preview will be adjusted dynamically to the drop area
DragPreviewShowsContentPixmap = 0x0800,///< If opaque undocking is disabled, the created drag preview window shows a copy of the content of the dock widget / dock are that is dragged
DragPreviewHasWindowFrame = 0x1000,///< If opaque undocking is disabled, then this flag configures if the drag preview is frameless or looks like a real window
DefaultConfig = ActiveTabHasCloseButton
| DockAreaHasCloseButton
| OpaqueSplitterResize
| XmlCompressionEnabled
| OpaqueUndocking, ///< the default configuration
DefaultNonOpaqueConfig = ActiveTabHasCloseButton
| DockAreaHasCloseButton
| XmlCompressionEnabled
AlwaysShowTabs = 0x2000,///< If this option is enabled, the tab of a dock widget is always displayed - even if it is the only visible dock widget in a floating widget.
DockAreaHasUndockButton = 0x4000, //!< If the flag is set each dock area has an undock button
DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button
DockAreaHideDisabledButtons = 0x10000, //!< If the flag is set disabled dock area buttons will not appear on the tollbar at all (enabling them will bring them back)
DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set dock area will disable a tabs menu button when there is only one tab in the area
FloatingContainerHasWidgetTitle = 0x40000,
FloatingContainerHasWidgetIcon = 0x80000,
DefaultDockAreaButtons = DockAreaHasCloseButton
| DockAreaHasUndockButton
| DockAreaHasTabsMenuButton,///< default configuration of dock area title bar buttons
DefaultBaseConfig = DefaultDockAreaButtons
| ActiveTabHasCloseButton
| XmlCompressionEnabled
| FloatingContainerHasWidgetTitle,///< default base configuration settings
DefaultOpaqueConfig = DefaultBaseConfig
| OpaqueSplitterResize
| OpaqueUndocking, ///< the default configuration with opaque operations - this may cause issues if ActiveX or Qt 3D windows are involved
DefaultNonOpaqueConfig = DefaultBaseConfig
| DragPreviewShowsContentPixmap, ///< the default configuration for non opaque operations
NonOpaqueWithWindowFrame = ActiveTabHasCloseButton
| DockAreaHasCloseButton
| XmlCompressionEnabled
| DragPreviewShowsContentPixmap
NonOpaqueWithWindowFrame = DefaultNonOpaqueConfig
| DragPreviewHasWindowFrame ///< the default configuration for non opaque operations that show a real window with frame
};
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
@@ -180,12 +196,12 @@ public:
* Before you create any dock widgets, you should properly setup the
* configuration flags via setConfigFlags().
*/
CDockManager(QWidget* parent = 0);
CDockManager(QWidget* parent = nullptr);
/**
* Virtual Destructor
*/
virtual ~CDockManager();
virtual ~CDockManager() override;
/**
* This function returns the global configuration flags
@@ -194,15 +210,22 @@ public:
/**
* Sets the global configuration flags for the whole docking system.
* Call this function before you create your first dock widget.
* Call this function before you create the dock manager and before
* your create the first dock widget.
*/
static void setConfigFlags(const ConfigFlags Flags);
/**
* Set a certain config flag
* Set a certain config flag.
* \see setConfigFlags()
*/
static void setConfigFlag(eConfigFlag Flag, bool On = true);
/**
* Returns true if the given config flag is set
*/
static bool testConfigFlag(eConfigFlag Flag);
/**
* Returns the global icon provider.
* The icon provider enables the use of custom icons in case using
@@ -281,7 +304,7 @@ public:
* This function always return 0 because the main window is always behind
* any floating widget
*/
virtual unsigned int zOrderIndex() const;
unsigned int zOrderIndex() const override;
/**
* Saves the current state of the dockmanger and all its dock widgets
@@ -430,10 +453,17 @@ signals:
/**
* This signal is emitted if the dock manager finished opening a
* perspective
* perspective.
*/
void perspectiveOpened(const QString& PerspectiveName);
/**
* This signal is emitted, if a new floating widget has been created.
* An application can use this signal to e.g. subscribe to events of
* the newly created window.
*/
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
/**
* This signal is emitted, if a new DockArea has been created.
* An application can use this signal to set custom icons or custom

View File

@@ -380,13 +380,14 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
return Result;
}
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(d->TargetWidget.data());
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data());
if (!DockArea)
{
return Result;
}
if (DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(QCursor::pos())))
if (DockArea->allowedAreas().testFlag(CenterDockWidgetArea)
&& DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(QCursor::pos())))
{
return CenterDockWidgetArea;
}
@@ -395,6 +396,20 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
}
//============================================================================
DockWidgetArea CDockOverlay::visibleDropAreaUnderCursor() const
{
if (isHidden() || !d->DropPreviewEnabled)
{
return InvalidDockWidgetArea;
}
else
{
return dropAreaUnderCursor();
}
}
//============================================================================
DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
{
@@ -631,7 +646,7 @@ void CDockOverlayCross::updateOverlayIcons()
{
d->updateDropIndicatorIcon(Widget);
}
#if QT_VESION >= 0x050600
#if QT_VERSION >= 0x050600
d->LastDevicePixelRatio = devicePixelRatioF();
#else
d->LastDevicePixelRatio = devicePixelRatio();

View File

@@ -81,6 +81,13 @@ public:
*/
DockWidgetArea dropAreaUnderCursor() const;
/**
* This function returns the same like dropAreaUnderCursor() if this
* overlay is not hidden and if drop preview is enabled and returns
* InvalidDockWidgetArea if it is hidden or drop preview is disabled.
*/
DockWidgetArea visibleDropAreaUnderCursor() const;
/**
* Show the drop overly for the given target widget
*/

View File

@@ -88,6 +88,20 @@ bool CDockSplitter::hasVisibleContent() const
return false;
}
//============================================================================
QWidget* CDockSplitter::firstWidget() const
{
return (count() > 0) ? widget(0) : nullptr;
}
//============================================================================
QWidget* CDockSplitter::lastWidget() const
{
return (count() > 0) ? widget(count() - 1) : nullptr;
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -61,6 +61,16 @@ public:
* Returns true, if any of the internal widgets is visible
*/
bool hasVisibleContent() const;
/**
* Returns first widget or nullptr if splitter is empty
*/
QWidget* firstWidget() const;
/**
* Returns last widget of nullptr is splitter is empty
*/
QWidget* lastWidget() const;
}; // class CDockSplitter
} // namespace ads

View File

@@ -54,6 +54,7 @@
#include "DockManager.h"
#include "FloatingDockContainer.h"
#include "DockSplitter.h"
#include "DockComponentsFactory.h"
#include "ads_globals.h"
@@ -80,6 +81,7 @@ struct DockWidgetPrivate
QSize ToolBarIconSizeDocked = QSize(16, 16);
QSize ToolBarIconSizeFloating = QSize(24, 24);
bool IsFloatingTopLevel = false;
QList<QAction*> TitleBarActions;
/**
* Private data constructor
@@ -171,6 +173,12 @@ void DockWidgetPrivate::updateParentDockArea()
return;
}
// we don't need to change the current tab if the
// current dock widget is not the one being closed
if (DockArea->currentDockWidget() != _this){
return;
}
auto NextDockWidget = DockArea->nextOpenDockWidget(_this);
if (NextDockWidget)
{
@@ -219,7 +227,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
setWindowTitle(title);
setObjectName(title);
d->TabWidget = new CDockWidgetTab(this);
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
d->ToggleViewAction = new QAction(title, this);
d->ToggleViewAction->setCheckable(true);
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
@@ -807,6 +815,7 @@ bool CDockWidget::closeDockWidgetInternal(bool ForceClose)
}
}
deleteDockWidget();
emit closed();
}
else
{
@@ -817,6 +826,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
//---------------------------------------------------------------------------

View File

@@ -74,6 +74,7 @@ protected:
friend class CDockAreaTabBar;
friend class CDockWidgetTab;
friend struct DockWidgetTabPrivate;
friend struct DockAreaTitleBarPrivate;
/**
* Assigns the dock manager that manages this dock widget
@@ -345,13 +346,10 @@ public:
QIcon icon() const;
/**
* If the WithToolBar layout flag is enabled, then this function returns
* the dock widget toolbar. If the flag is disabled, the function returns
* a nullptr.
* This function returns the dock widget top tool bar.
* If no toolbar is assigned, this function returns nullptr. To get a vaild
* toolbar you either need to create a default empty toolbar via
* createDefaultToolBar() function or you need to assign you custom
* createDefaultToolBar() function or you need to assign your custom
* toolbar via setToolBar().
*/
QToolBar* toolBar() const;
@@ -401,6 +399,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
/**

View File

@@ -68,6 +68,7 @@ struct DockWidgetTabPrivate
QLabel* IconLabel = nullptr;
tTabLabel* TitleLabel;
QPoint GlobalDragStartMousePosition;
QPoint DragStartMousePosition;
bool IsActiveTab = false;
CDockAreaWidget* DockArea = nullptr;
eDragState DragState = DraggingInactive;
@@ -100,15 +101,6 @@ struct DockWidgetTabPrivate
return this->DragState == dragState;
}
/**
* Returns true if the given global point is inside the title area geometry
* rectangle.
* The position is given as global position.
*/
bool titleAreaGeometryContains(const QPoint& GlobalPos) const
{
return DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(GlobalPos));
}
/**
* Starts floating of the dock widget that belongs to this title bar
@@ -159,6 +151,15 @@ struct DockWidgetTabPrivate
return w;
}
}
/**
* Saves the drag start position in global and local coordinates
*/
void saveDragStartMousePosition(const QPoint& GlobalPos)
{
GlobalDragStartMousePosition = GlobalPos;
DragStartMousePosition = _this->mapFromGlobal(GlobalPos);
}
};
// struct DockWidgetTabPrivate
@@ -179,23 +180,15 @@ void DockWidgetTabPrivate::createLayout()
TitleLabel->setText(DockWidget->windowTitle());
TitleLabel->setObjectName("dockWidgetTabLabel");
TitleLabel->setAlignment(Qt::AlignCenter);
_this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool)));
CloseButton = createCloseButton();
CloseButton->setObjectName("tabCloseButton");
QIcon CloseIcon = CDockManager::iconProvider().customIcon(TabCloseIcon);
if (CloseIcon.isNull())
{
// The standard icons do does not look good on high DPI screens
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
}
CloseButton->setIcon(CloseIcon);
internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, TabCloseIcon);
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
_this->onDockWidgetFeaturesChanged();
#ifndef QT_NO_TOOLTIP
CloseButton->setToolTip(QObject::tr("Close Tab"));
#endif
internal::setToolTip(CloseButton, QObject::tr("Close Tab"));
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
QFontMetrics fm(TitleLabel->font());
@@ -222,6 +215,8 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
Distance.setY(0);
auto TargetPos = Distance + TabDragStartPosition;
TargetPos.rx() = qMax(TargetPos.x(), 0);
TargetPos.rx() = qMin(_this->parentWidget()->rect().right() - _this->width() + 1, TargetPos.rx());
_this->move(TargetPos);
_this->raise();
}
@@ -246,7 +241,6 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
ADS_PRINT("startFloating");
DragState = DraggingState;
auto DragStartMousePosition = _this->mapFromGlobal(GlobalDragStartMousePosition);
QSize Size = DockArea->size();
IFloatingWidget* FloatingWidget = nullptr;
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
@@ -304,7 +298,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
if (ev->button() == Qt::LeftButton)
{
ev->accept();
d->GlobalDragStartMousePosition = ev->globalPos();
d->saveDragStartMousePosition(ev->globalPos());
d->DragState = DraggingMousePressed;
emit clicked();
return;
@@ -321,6 +315,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
{
auto CurrentDragState = d->DragState;
d->GlobalDragStartMousePosition = QPoint();
d->DragStartMousePosition = QPoint();
d->DragState = DraggingInactive;
switch (CurrentDragState)
@@ -371,9 +366,11 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
d->moveTab(ev);
}
auto MappedPos = mapToParent(ev->pos());
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
// Maybe a fixed drag distance is better here ?
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
if (DragDistanceY >= CDockManager::startDragDistance())
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
{
// If this is the last dock area in a dock container with only
// one single dock widget it does not make sense to move it to a new
@@ -385,14 +382,19 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
return;
}
// Floating is only allowed for widgets that are movable
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
// Floating is only allowed for widgets that are floatable
// If we do non opaque undocking, then can create the drag preview
// if the widget is movable.
auto Features = d->DockWidget->features();
if (Features.testFlag(CDockWidget::DockWidgetFloatable)
|| (Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)))
{
// If we undock, we need to restore the initial position of this
// tab because it looks strange if it remains on its dragged position
if (d->isDraggingState(DraggingTab) && !CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking))
{
this->move(d->TabDragStartPosition);
parentWidget()->layout()->update();
}
d->startFloating();
}
@@ -424,10 +426,16 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
return;
}
d->GlobalDragStartMousePosition = ev->globalPos();
d->saveDragStartMousePosition(ev->globalPos());
QMenu Menu(this);
const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable);
const bool isNotOnlyTabInContainer = !d->DockArea->dockContainer()->hasTopLevelDockWidget();
const bool isDetachable = isFloatable && isNotOnlyTabInContainer;
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
Action->setEnabled(isDetachable);
Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
Action->setEnabled(isClosable());
@@ -462,6 +470,7 @@ void CDockWidgetTab::setActiveTab(bool active)
d->TitleLabel->style()->unpolish(d->TitleLabel);
d->TitleLabel->style()->polish(d->TitleLabel);
update();
updateGeometry();
emit activeTabChanged();
}
@@ -502,9 +511,7 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
d->IconLabel = new QLabel();
d->IconLabel->setAlignment(Qt::AlignVCenter);
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
#ifndef QT_NO_TOOLTIP
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
#endif
internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip());
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
}
@@ -549,7 +556,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{
d->GlobalDragStartMousePosition = event->globalPos();
d->saveDragStartMousePosition(event->globalPos());
d->startFloating(DraggingInactive);
}
@@ -571,6 +578,11 @@ void CDockWidgetTab::setText(const QString& title)
d->TitleLabel->setText(title);
}
bool CDockWidgetTab::isTitleElided() const
{
return d->TitleLabel->isElided();
}
//============================================================================
@@ -587,7 +599,8 @@ void CDockWidgetTab::detachDockWidget()
{
return;
}
d->GlobalDragStartMousePosition = QCursor::pos();
d->saveDragStartMousePosition(QCursor::pos());
d->startFloating(DraggingInactive);
}

View File

@@ -94,11 +94,6 @@ public:
*/
void setActiveTab(bool active);
/**
* Returns the dock widget this title widget belongs to
*/
CDockWidget* dockWidget() const;
/**
* Sets the dock area widget the dockWidget returned by dockWidget()
* function belongs to.
@@ -112,6 +107,11 @@ public:
*/
CDockAreaWidget* dockAreaWidget() const;
/**
* Returns the dock widget this title widget belongs to
*/
CDockWidget* dockWidget() const;
/**
* Sets the icon to show in title bar
*/
@@ -132,6 +132,11 @@ public:
*/
void setText(const QString& title);
/**
* Returns true if text is elided on the tab's title
*/
bool isTitleElided() const;
/**
* This function returns true if the assigned dock widget is closable
*/
@@ -152,6 +157,7 @@ signals:
void closeRequested();
void closeOtherTabsRequested();
void moved(const QPoint& GlobalPos);
void elidedChanged(bool elided);
}; // class DockWidgetTab
}
// namespace ads

View File

@@ -41,6 +41,7 @@ struct ElidingLabelPrivate
CElidingLabel* _this;
Qt::TextElideMode ElideMode = Qt::ElideNone;
QString Text;
bool IsElided = false;
ElidingLabelPrivate(CElidingLabel* _public) : _this(_public) {}
@@ -69,6 +70,12 @@ void ElidingLabelPrivate::elideText(int Width)
{
str = Text.at(0);
}
bool WasElided = IsElided;
IsElided = str != Text;
if(IsElided != WasElided)
{
emit _this->elidedChanged(IsElided);
}
_this->QLabel::setText(str);
}
@@ -88,9 +95,7 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla
d(new ElidingLabelPrivate(this))
{
d->Text = text;
#ifndef QT_NO_TOOLTIP
setToolTip(text);
#endif
internal::setToolTip(this, text);
}
@@ -115,6 +120,12 @@ void CElidingLabel::setElideMode(Qt::TextElideMode mode)
d->elideText(size().width());
}
//============================================================================
bool CElidingLabel::isElided() const
{
return d->IsElided;
}
//============================================================================
void CElidingLabel::mouseReleaseEvent(QMouseEvent* event)
@@ -193,9 +204,7 @@ void CElidingLabel::setText(const QString &text)
else
{
d->Text = text;
#ifndef QT_NO_TOOLTIP
setToolTip( text );
#endif
internal::setToolTip(this, text);
d->elideText(this->size().width());
}
}

View File

@@ -73,6 +73,10 @@ public:
*/
void setElideMode(Qt::TextElideMode mode);
/**
* This function indicates whether the text on this label is currently elided
*/
bool isElided() const;
public: // reimplements QLabel ----------------------------------------------
virtual QSize minimumSizeHint() const override;
@@ -91,6 +95,11 @@ signals:
* This signal is emitted if the user does a double click on the label
*/
void doubleClicked();
/**
* This signal is emitted when isElided() state of this label is changed
*/
void elidedChanged(bool elided);
}; //class CElidingLabel
} // namespace QtLabb

View File

@@ -79,6 +79,14 @@ struct FloatingDockContainerPrivate
void titleMouseReleaseEvent();
void updateDropOverlays(const QPoint &GlobalPos);
/**
* Returns true if the given config flag is set
*/
static bool testConfigFlag(CDockManager::eConfigFlag Flag)
{
return CDockManager::configFlags().testFlag(Flag);
}
/**
* Tests is a certain state is active
*/
@@ -100,6 +108,31 @@ struct FloatingDockContainerPrivate
_this->setWindowTitle(Text);
#endif
}
void reflectCurrentWidget(CDockWidget* CurrentWidget)
{
// reflect CurrentWidget's title if configured to do so, otherwise display application name as window title
if (testConfigFlag(CDockManager::FloatingContainerHasWidgetTitle))
{
setWindowTitle(CurrentWidget->windowTitle());
}
else
{
setWindowTitle(qApp->applicationDisplayName());
}
// reflect CurrentWidget's icon if configured to do so, otherwise display application icon as window icon
QIcon CurrentWidgetIcon = CurrentWidget->icon();
if (testConfigFlag(CDockManager::FloatingContainerHasWidgetIcon)
&& !CurrentWidgetIcon.isNull())
{
_this->setWindowIcon(CurrentWidget->icon());
}
else
{
_this->setWindowIcon(QApplication::windowIcon());
}
}
};
// struct FloatingDockContainerPrivate
@@ -207,7 +240,7 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint &GlobalPos)
{
DockAreaOverlay->enableDropPreview(true);
DockAreaOverlay->setAllowedAreas(
(VisibleDockAreas == 1) ? NoDockWidgetArea : AllDockAreas);
(VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas());
DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea);
// A CenterDockWidgetArea for the dockAreaOverlay() indicates that
@@ -537,8 +570,8 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
if (TopLevelDockArea)
{
d->SingleDockArea = TopLevelDockArea;
d->setWindowTitle(
d->SingleDockArea->currentDockWidget()->windowTitle());
CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget();
d->reflectCurrentWidget(CurrentWidget);
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
}
@@ -551,6 +584,7 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
d->SingleDockArea = nullptr;
}
d->setWindowTitle(qApp->applicationDisplayName());
setWindowIcon(QApplication::windowIcon());
}
}
@@ -560,11 +594,13 @@ void CFloatingDockContainer::updateWindowTitle()
auto TopLevelDockArea = d->DockContainer->topLevelDockArea();
if (TopLevelDockArea)
{
d->setWindowTitle(TopLevelDockArea->currentDockWidget()->windowTitle());
CDockWidget* CurrentWidget = TopLevelDockArea->currentDockWidget();
d->reflectCurrentWidget(CurrentWidget);
}
else
{
d->setWindowTitle(qApp->applicationDisplayName());
setWindowIcon(QApplication::windowIcon());
}
}
@@ -572,7 +608,8 @@ void CFloatingDockContainer::updateWindowTitle()
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
{
Q_UNUSED(Index);
d->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget();
d->reflectCurrentWidget(CurrentWidget);
}
//============================================================================

View File

@@ -157,7 +157,7 @@ protected:
* Moves the widget to a new position relative to the position given when
* startFloating() was called
*/
void moveFloating();
void moveFloating() override;
/**
* Restores the state from given stream.

View File

@@ -40,6 +40,7 @@ struct FloatingDragPreviewPrivate
qreal WindowOpacity;
bool Hidden = false;
QPixmap ContentPreviewPixmap;
bool Canceled = false;
/**
@@ -59,6 +60,7 @@ struct FloatingDragPreviewPrivate
*/
void cancelDragging()
{
Canceled = true;
emit _this->draggingCanceled();
DockManager->containerOverlay()->hideOverlay();
DockManager->dockAreaOverlay()->hideOverlay();
@@ -85,11 +87,6 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
continue;
}
/*if (DockContainer == ContainerWidget)
{
continue;
}*/
QPoint MappedPos = ContainerWidget->mapFromGlobal(GlobalPos);
if (ContainerWidget->rect().contains(MappedPos))
{
@@ -127,7 +124,7 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
{
DockAreaOverlay->enableDropPreview(true);
DockAreaOverlay->setAllowedAreas(
(VisibleDockAreas == 1) ? NoDockWidgetArea : AllDockAreas);
(VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas());
DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea);
// A CenterDockWidgetArea for the dockAreaOverlay() indicates that
@@ -148,6 +145,14 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
else
{
DockAreaOverlay->hideOverlay();
// If there is only one single visible dock area in a container, then
// it does not make sense to show a dock overlay because the dock area
// would be removed and inserted at the same position
if (VisibleDockAreas <= 1)
{
ContainerOverlay->hide();
}
if (DockArea == ContentSourceArea && InvalidDockWidgetArea == ContainerDropArea)
{
DropContainer = nullptr;
@@ -207,12 +212,9 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
SLOT(onApplicationStateChanged(Qt::ApplicationState)));
#ifdef Q_OS_LINUX
// In Windows this widget directly receives the escape key press events
// in Linux we need to install an event filter for the given Content
// widget to receive the escape key press
Content->installEventFilter(this);
#endif
// The only safe way to receive escape key presses is to install an event
// filter for the application object
qApp->installEventFilter(this);
}
@@ -284,35 +286,46 @@ void CFloatingDragPreview::moveEvent(QMoveEvent *event)
void CFloatingDragPreview::finishDragging()
{
ADS_PRINT("CFloatingDragPreview::finishDragging");
auto DockDropArea = d->DockManager->dockAreaOverlay()->dropAreaUnderCursor();
auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
bool DropPossible = (DockDropArea != InvalidDockWidgetArea) || (ContainerDropArea != InvalidDockWidgetArea);
if (d->DropContainer && DropPossible)
auto DockDropArea = d->DockManager->dockAreaOverlay()->visibleDropAreaUnderCursor();
auto ContainerDropArea = d->DockManager->containerOverlay()->visibleDropAreaUnderCursor();
if (d->DropContainer && (DockDropArea != InvalidDockWidgetArea))
{
d->DropContainer->dropWidget(d->Content, QCursor::pos());
d->DropContainer->dropWidget(d->Content, DockDropArea, d->DropContainer->dockAreaAt(QCursor::pos()));
}
else if (d->DropContainer && (ContainerDropArea != InvalidDockWidgetArea))
{
d->DropContainer->dropWidget(d->Content, ContainerDropArea, nullptr);
}
else
{
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(d->Content);
CFloatingDockContainer* FloatingWidget;
if (DockWidget)
CFloatingDockContainer* FloatingWidget = nullptr;
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{
FloatingWidget = new CFloatingDockContainer(DockWidget);
}
else
{
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->Content);
FloatingWidget = new CFloatingDockContainer(DockArea);
if (DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
FloatingWidget = new CFloatingDockContainer(DockArea);
}
}
FloatingWidget->setGeometry(this->geometry());
FloatingWidget->show();
if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
if (FloatingWidget)
{
QApplication::processEvents();
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height();
QRect FixedGeometry = this->geometry();
FixedGeometry.adjust(0, FrameHeight, 0, 0);
FloatingWidget->setGeometry(FixedGeometry);
FloatingWidget->setGeometry(this->geometry());
FloatingWidget->show();
if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
{
QApplication::processEvents();
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height();
QRect FixedGeometry = this->geometry();
FixedGeometry.adjust(0, FrameHeight, 0, 0);
FloatingWidget->setGeometry(FixedGeometry);
}
}
}
@@ -355,18 +368,6 @@ void CFloatingDragPreview::paintEvent(QPaintEvent* event)
}
}
//============================================================================
void CFloatingDragPreview::keyPressEvent(QKeyEvent *event)
{
Super::keyPressEvent(event);
if (event->key() == Qt::Key_Escape)
{
d->cancelDragging();
}
}
//============================================================================
void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state)
{
@@ -383,12 +384,12 @@ void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state)
bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
if (event->type() == QEvent::KeyPress)
if (!d->Canceled && event->type() == QEvent::KeyPress)
{
QKeyEvent* e = static_cast<QKeyEvent*>(event);
if (e->key() == Qt::Key_Escape)
{
d->Content->removeEventFilter(this);
watched->removeEventFilter(this);
d->cancelDragging();
}
}
@@ -398,7 +399,6 @@ bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event)
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -49,11 +49,6 @@ protected:
*/
virtual void paintEvent(QPaintEvent *e) override;
/**
* Cancel non opaque undocking with escape key
*/
virtual void keyPressEvent(QKeyEvent *event) override;
/**
* The content is a DockArea or a DockWidget
*/

View File

@@ -30,8 +30,11 @@
//============================================================================
#include <QVariant>
#include <QPainter>
#include <QAbstractButton>
#include "DockSplitter.h"
#include "DockManager.h"
#include "IconProvider.h"
#include "ads_globals.h"
@@ -90,6 +93,31 @@ void hideEmptyParentSplitters(CDockSplitter* Splitter)
}
}
//============================================================================
void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap,
ads::eIcon CustomIconId)
{
// First we try to use custom icons if available
QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId);
if (!Icon.isNull())
{
Button->setIcon(Icon);
return;
}
#ifdef Q_OS_LINUX
Button->setIcon(Button->style()->standardIcon(StandarPixmap));
#else
// The standard icons does not look good on high DPI screens so we create
// our own "standard" icon here.
QPixmap normalPixmap = Button->style()->standardPixmap(StandarPixmap, 0, Button);
Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
Icon.addPixmap(normalPixmap, QIcon::Normal);
Button->setIcon(Icon);
#endif
}
} // namespace internal
} // namespace ads

View File

@@ -35,6 +35,9 @@
#include <QPixmap>
#include <QWidget>
#include <QDebug>
#include <QStyle>
class QAbstractButton;
#ifndef ADS_STATIC
#ifdef ADS_SHARED_EXPORT
@@ -215,6 +218,39 @@ void setFlag(T& Flags, typename T::enum_type flag, bool on = true)
#endif
}
/**
* Helper function for settings tooltips without cluttering the code with
* tests for preprocessor macros
*/
template <class QObjectPtr>
void setToolTip(QObjectPtr obj, const QString &tip)
{
#ifndef QT_NO_TOOLTIP
obj->setToolTip(tip);
#else
Q_UNUSED(obj);
Q_UNUSED(tip);
#endif
}
/**
* Helper function to set the icon of a certain button.
* Use this function to set the icons for the dock area and dock widget buttons.
* The function first uses the CustomIconId to get an icon from the
* CIconProvider. You can register your custom icons with the icon provider, if
* you do not want to use the default buttons and if you do not want to use
* stylesheets.
* If the IconProvider does not return a valid icon (icon is null), the function
* fetches the given standard pixmap from the QStyle.
* param[in] Button The button whose icons are to be set
* param[in] StandardPixmap The standard pixmap to be used for the button
* param[in] CustomIconId The identifier for the custom icon.
*/
void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap,
ads::eIcon CustomIconId);
} // namespace internal
} // namespace ads

View File

@@ -43,7 +43,8 @@ HEADERS += \
DockSplitter.h \
DockAreaTitleBar.h \
ElidingLabel.h \
IconProvider.h
IconProvider.h \
DockComponentsFactory.h
SOURCES += \
@@ -61,7 +62,8 @@ SOURCES += \
DockSplitter.cpp \
DockAreaTitleBar.cpp \
ElidingLabel.cpp \
IconProvider.cpp
IconProvider.cpp \
DockComponentsFactory.cpp
unix {

View File

@@ -59,11 +59,9 @@ ads--CDockWidget
border-width: 1px 0 0 0;
}
#tabsMenuButton,
#closeButton,
#undockButton
ads--CTitleBarButton
{
padding: 0px -2px;
padding: 0px 0px;
}

View File

@@ -59,14 +59,14 @@ ads--CDockWidget
border-width: 1px 0 0 0;
}
#tabsMenuButton,
#closeButton,
#undockButton
ads--CTitleBarButton
{
padding: 0px -2px;
padding: 0px 0px;
}
QScrollArea#dockWidgetScrollArea
{
padding: 0px;