| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include "extensionpanel.h" |
| 22 |
#include <QPainter> |
| 23 |
#include "application.h" |
| 24 |
#include "controller/signalmanager.h" |
| 25 |
#include "darrowbutton.h" |
| 26 |
#include <DFontSizeManager> |
| 27 |
|
| 28 |
using namespace Dtk::Widget; |
| 29 |
|
| 30 |
namespace { |
| 31 |
|
| 32 |
// const int CONTROL_BUTTON_WIDTH = 20; |
| 33 |
// const int CONTROL_BUTTON_HEIGHT = 60; |
| 34 |
// const int CONTROL_BUTTON_CUBIC_LENGTH = 30; |
| 35 |
const int EXTENSION_PANEL_WIDTH = 300 + 20; |
| 36 |
// const int EXTENSION_PANEL_MAX_WIDTH = 340; |
| 37 |
|
| 38 |
const QColor DARK_COVERBRUSH = QColor(0, 0, 0, 100); |
| 39 |
const QColor LIGHT_COVERBRUSH = QColor(255, 255, 255, 179); |
| 40 |
//const int ANIMATION_DURATION = 500; |
| 41 |
const QEasingCurve ANIMATION_EASING_CURVE = QEasingCurve::InOutCubic; |
| 42 |
} // namespace |
| 43 |
|
| 44 |
ExtensionPanel *ExtensionPanel::instance = nullptr; |
| 45 |
|
| 46 |
ExtensionPanel::ExtensionPanel(QWidget *parent) |
| 47 |
: DDialog(parent) |
| 48 |
{ |
| 49 |
this->setWindowTitle(tr("Photo info")); |
| 50 |
DFontSizeManager::instance()->bind(this, DFontSizeManager::T6, QFont::Medium); |
| 51 |
|
| 52 |
// m_contentLayout = new QVBoxLayout(this); |
| 53 |
// m_contentLayout->setContentsMargins(10, 0, 10, 0); |
| 54 |
// m_contentLayout->setSpacing(0); |
| 55 |
setFixedWidth(EXTENSION_PANEL_WIDTH); |
| 56 |
setFixedHeight(540); |
| 57 |
setContentLayoutContentsMargins(QMargins(0, 0, 0, 0)); |
| 58 |
setModal(true); |
| 59 |
} |
| 60 |
|
| 61 |
ExtensionPanel *ExtensionPanel::getInstance(QWidget *parent) |
| 62 |
{ |
| 63 |
if (instance == nullptr) { |
| 64 |
instance = new ExtensionPanel(parent); |
| 65 |
} |
| 66 |
return instance; |
| 67 |
} |
| 68 |
|
| 69 |
void ExtensionPanel::setContent(QWidget *content) |
| 70 |
{ |
| 71 |
if (content) { |
| 72 |
QLayoutItem *child; |
| 73 |
if ((child = this->layout()->takeAt(0)) != nullptr) { |
| 74 |
if (child->widget()) |
| 75 |
child->widget()->deleteLater(); |
| 76 |
delete child; |
| 77 |
} |
| 78 |
|
| 79 |
m_content = content; |
| 80 |
updateRectWithContent(); |
| 81 |
this->addContent(content); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
void ExtensionPanel::updateRectWithContent() |
| 86 |
{ |
| 87 |
connect(dApp->signalM, &SignalManager::extensionPanelHeight, this, |
| 88 |
[ = ](int height) { |
| 89 |
setFixedHeight(qMin(615, height + 5)); //tmp for imageinfo |
| 90 |
}); |
| 91 |
} |