All Classes Namespaces Functions Variables Enumerations Properties Pages
basedockwidget.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include <QLayout>
19 #include <QResizeEvent>
20 
21 #include "basedockwidget.h"
22 #include "platformhandler.h"
23 
24 BaseDockWidget::BaseDockWidget(QWidget* pParent)
25 : QDockWidget(pParent, Qt::Tool)
26 {
27 
28 #ifdef __APPLE__
29  if (PlatformHandler::isDarkMode())
30  {
31  setStyleSheet("QDockWidget::title { background: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #4e4f4d, stop: 1 #424241); "
32  "background-repeat: repeat-x; text-align: center;"
33  "border-style: solid; border-bottom-color: #000000;"
34  "border-width: 1px; }");
35  }
36 #endif
37 
38 }
39 
40 BaseDockWidget::~BaseDockWidget()
41 {
42 }
43 
44 void BaseDockWidget::resizeEvent(QResizeEvent *event)
45 {
47 
48  // Not sure where the -2 comes from, but the event width is always 2 more than what is passed to FlowLayout::setGeometry
49  int minHeight = getMinHeightForWidth(event->size().width() - 2);
50 
51  if (minHeight < 0) return;
52 
53 #ifdef __APPLE__
54  // For some reason the behavior of minimumSize and the margin changes on mac when floating, so we need to do this
55 #else
56  minHeight += layout()->margin()*2;
57 #endif
58  setMinimumSize(QSize(layout()->minimumSize().width(), minHeight));
59 }
60 
61 int BaseDockWidget::getMinHeightForWidth(int width)
62 {
63  Q_UNUSED(width)
64  return -1;
65 }
QLayout * layout() const const
int width() const const
int width() const const
void setMinimumSize(const QSize &)
const QSize & size() const const
virtual void resizeEvent(QResizeEvent *event)