Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
tooloptionwidget.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#include "tooloptionwidget.h"
18#include "ui_tooloptions.h"
19
20#include <QSettings>
21#include <QDebug>
22
23#include "cameraoptionswidget.h"
24#include "bucketoptionswidget.h"
25#include "strokeoptionswidget.h"
26#include "transformoptionswidget.h"
27#include "spinslider.h"
28#include "editor.h"
29#include "util.h"
30#include "layer.h"
31#include "layermanager.h"
32#include "stroketool.h"
33#include "toolmanager.h"
34#include "basewidget.h"
35
36
37ToolOptionWidget::ToolOptionWidget(QWidget* parent) : BaseDockWidget(parent)
38{
39 setWindowTitle(tr("Options", "Window title of tool option panel like pen width, feather etc.."));
40
41 QWidget* innerWidget = new QWidget;
42 setWidget(innerWidget);
43 ui = new Ui::ToolOptions;
44 ui->setupUi(innerWidget);
45}
46
47ToolOptionWidget::~ToolOptionWidget()
48{
49 delete ui;
50}
51
52void ToolOptionWidget::initUI()
53{
54 mBucketOptionsWidget = new BucketOptionsWidget(editor(), this);
55 mCameraOptionsWidget = new CameraOptionsWidget(editor(), this);
56
57 mBucketOptionsWidget->setHidden(true);
58 mCameraOptionsWidget->setHidden(true);
59
60 mStrokeOptionsWidget = new StrokeOptionsWidget(editor(), this);
61 mTransformOptionsWidget = new TransformOptionsWidget(editor(), this);
62 ui->scrollAreaWidgetContents->layout()->addWidget(mBucketOptionsWidget);
63 ui->scrollAreaWidgetContents->layout()->addWidget(mCameraOptionsWidget);
64 ui->scrollAreaWidgetContents->layout()->addWidget(mStrokeOptionsWidget);
65 ui->scrollAreaWidgetContents->layout()->addWidget(mTransformOptionsWidget);
66 ui->scrollAreaWidgetContents->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
67
68 makeConnectionToEditor(editor());
69 updateUI();
70}
71
72void ToolOptionWidget::updateUI()
73{
74 BaseTool* currentTool = editor()->tools()->currentTool();
75 Q_ASSERT(currentTool);
76
77 updateUIForTool(currentTool);
78}
79
80void ToolOptionWidget::makeConnectionToEditor(Editor* editor)
81{
82 connect(editor->tools(), &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged);
83 connect(editor->tools(), &ToolManager::toolsReset, this, &ToolOptionWidget::onToolsReset);
84 connect(editor->layers(), &LayerManager::currentLayerChanged, this, &ToolOptionWidget::onLayerChanged);
85}
86
87void ToolOptionWidget::setWidgetVisibility(BaseWidget* widget, bool isVisible)
88{
89 widget->setVisible(isVisible);
90
91 if (isVisible) {
92 widget->updateUI();
93 }
94}
95
96void ToolOptionWidget::updateUIForTool(BaseTool* tool)
97{
98 setWidgetVisibility(mBucketOptionsWidget, tool->type() == BUCKET);
99 setWidgetVisibility(mCameraOptionsWidget, tool->type() == CAMERA);
100 setWidgetVisibility(mStrokeOptionsWidget, editor()->tools()->isStrokeTool(tool));
101 setWidgetVisibility(mTransformOptionsWidget, editor()->tools()->isTransformTool(tool));
102}
103
104void ToolOptionWidget::onLayerChanged(int layerIndex)
105{
106 LayerManager* layerManager = editor()->layers();
107 Layer* layer = layerManager->getLayer(layerIndex);
108 if (layer->type() != layerManager->currentLayer()->type()) {
109 return;
110 }
111
112 updateUIForTool(editor()->tools()->currentTool());
113}
114
115void ToolOptionWidget::onToolChanged(ToolType toolType)
116{
117 BaseTool* tool = editor()->tools()->getTool(toolType);
118 updateUIForTool(tool);
119}
120
121void ToolOptionWidget::onToolsReset()
122{
123 updateUIForTool(editor()->tools()->currentTool());
124}
BaseDockWidget
Definition: basedockwidget.h:27
BaseTool
Definition: basetool.h:47
BaseWidget
Definition: basewidget.h:24
BucketOptionsWidget
Definition: bucketoptionswidget.h:35
CameraOptionsWidget
Definition: cameraoptionswidget.h:33
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
LayerManager
Definition: layermanager.h:31
StrokeOptionsWidget
Definition: strokeoptionswidget.h:20
TransformOptionsWidget
Definition: transformoptionswidget.h:33
QDockWidget::widget
QWidget * widget() const const
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSizePolicy::MinimumExpanding
MinimumExpanding
QSpacerItem
QWidget
QWidget::setHidden
void setHidden(bool hidden)
QWidget::setVisible
virtual void setVisible(bool visible)
Generated on Tue Jan 6 2026 11:38:51 for Pencil2D by doxygen 1.9.6 based on revision f91a96748ec6712509b9b0ff47979db9c34d556f