Changeset View
Changeset View
Standalone View
Standalone View
sublime/idealbuttonbarwidget.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 85 | { | |||
---|---|---|---|---|---|
87 | const QString title = m_dock->view()->document()->title(); | 87 | const QString title = m_dock->view()->document()->title(); | ||
88 | setText(widget->isEnabled() ? title : QStringLiteral("(%1)").arg(title)); | 88 | setText(widget->isEnabled() ? title : QStringLiteral("(%1)").arg(title)); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | QPointer<IdealDockWidget> m_dock; | 91 | QPointer<IdealDockWidget> m_dock; | ||
92 | QPointer<IdealToolButton> m_button; | 92 | QPointer<IdealToolButton> m_button; | ||
93 | }; | 93 | }; | ||
94 | 94 | | |||
95 | class Sublime::LockButton : public IdealToolButton | ||||
96 | { | ||||
97 | public: | ||||
98 | LockButton(IdealButtonBarWidget* barWidget) | ||||
99 | : IdealToolButton(barWidget->area(), barWidget) | ||||
100 | , _barWidget(barWidget) | ||||
101 | { | ||||
102 | QAction* lockAction = new QAction(this); | ||||
103 | lockAction->setCheckable(true); | ||||
104 | lockAction->setToolTip(i18nc("@info:tooltip", "Lock/Unlock the Panel")); | ||||
105 | setDefaultAction(lockAction); | ||||
106 | | ||||
107 | setLocked(barWidget->isLocked()); | ||||
108 | setEnabled(barWidget->isShown()); | ||||
109 | | ||||
110 | connect(lockAction, &QAction::toggled, this, &LockButton::setLocked); | ||||
111 | } | ||||
112 | | ||||
113 | bool isLocked() | ||||
114 | { | ||||
115 | return defaultAction()->isChecked(); | ||||
116 | } | ||||
117 | | ||||
118 | void setLocked(bool lockValue) | ||||
119 | { | ||||
120 | defaultAction()->setIcon(lockIcon(lockValue)); | ||||
121 | | ||||
122 | | ||||
123 | if (isLocked() != lockValue) | ||||
124 | defaultAction()->setChecked(lockValue); | ||||
125 | | ||||
126 | if (_barWidget->isLocked() != lockValue) | ||||
127 | _barWidget->setLocked(lockValue); | ||||
128 | } | ||||
129 | | ||||
130 | QSize sizeHint() const override | ||||
131 | { | ||||
132 | QSize size = IdealToolButton::sizeHint(); | ||||
133 | | ||||
134 | size.setHeight(std::min(size.height(), size.width())); | ||||
135 | size.setWidth(size.height()); | ||||
136 | | ||||
137 | return size; | ||||
138 | } | ||||
139 | | ||||
140 | private: | ||||
141 | QIcon lockIcon(bool lockValue) | ||||
142 | { | ||||
143 | if (lockValue) | ||||
144 | return QIcon::fromTheme("lock"); | ||||
145 | else | ||||
146 | return QIcon::fromTheme("unlock"); | ||||
147 | } | ||||
148 | | ||||
149 | IdealButtonBarWidget* _barWidget; | ||||
150 | }; | ||||
151 | | ||||
95 | IdealButtonBarWidget::IdealButtonBarWidget(Qt::DockWidgetArea area, | 152 | IdealButtonBarWidget::IdealButtonBarWidget(Qt::DockWidgetArea area, | ||
96 | IdealController *controller, Sublime::MainWindow *parent) | 153 | IdealController *controller, Sublime::MainWindow *parent) | ||
97 | : QWidget(parent) | 154 | : QWidget(parent) | ||
98 | , _area(area) | 155 | , _area(area) | ||
99 | , _controller(controller) | 156 | , _controller(controller) | ||
100 | , _corner(nullptr) | 157 | , _corner(nullptr) | ||
101 | , _showState(false) | 158 | , _showState(false) | ||
159 | , _isLocked(false) | ||||
160 | , _lockButton(nullptr) | ||||
102 | { | 161 | { | ||
103 | setContextMenuPolicy(Qt::CustomContextMenu); | 162 | setContextMenuPolicy(Qt::CustomContextMenu); | ||
104 | setToolTip(i18nc("@info:tooltip", "Right click to add new tool views.")); | 163 | setToolTip(i18nc("@info:tooltip", "Right click to add new tool views.")); | ||
105 | 164 | | |||
106 | if (area == Qt::BottomDockWidgetArea) | 165 | if (area == Qt::BottomDockWidgetArea) | ||
107 | { | 166 | { | ||
108 | QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::RightToLeft, this); | 167 | QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::RightToLeft, this); | ||
168 | | ||||
109 | statusLayout->setMargin(0); | 169 | statusLayout->setMargin(0); | ||
110 | statusLayout->setSpacing(IDEAL_LAYOUT_SPACING); | 170 | statusLayout->setSpacing(IDEAL_LAYOUT_SPACING); | ||
111 | statusLayout->setContentsMargins(0, IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN); | 171 | statusLayout->setContentsMargins(0, IDEAL_LAYOUT_MARGIN, 0, IDEAL_LAYOUT_MARGIN); | ||
112 | 172 | | |||
113 | IdealButtonBarLayout *l = new IdealButtonBarLayout(orientation()); | 173 | IdealButtonBarLayout *l = new IdealButtonBarLayout(orientation()); | ||
114 | statusLayout->addLayout(l); | 174 | statusLayout->addLayout(l); | ||
115 | 175 | | |||
116 | _corner = new QWidget(this); | 176 | _corner = new QWidget(this); | ||
117 | QBoxLayout *cornerLayout = new QBoxLayout(QBoxLayout::LeftToRight, _corner); | 177 | QBoxLayout *cornerLayout = new QBoxLayout(QBoxLayout::LeftToRight, _corner); | ||
118 | cornerLayout->setMargin(0); | 178 | cornerLayout->setMargin(0); | ||
119 | cornerLayout->setSpacing(0); | 179 | cornerLayout->setSpacing(0); | ||
120 | statusLayout->addWidget(_corner); | 180 | statusLayout->addWidget(_corner); | ||
121 | statusLayout->addStretch(1); | 181 | statusLayout->addStretch(1); | ||
122 | } | 182 | } | ||
123 | else | 183 | else | ||
124 | (void) new IdealButtonBarLayout(orientation(), this); | 184 | (void) new IdealButtonBarLayout(orientation(), this); | ||
185 | | ||||
186 | KConfigGroup config = KSharedConfig::openConfig()->group("UiSettings"); | ||||
187 | _focusEditorOrHideDocks = config.readEntry(QStringLiteral("FocusEditorOrHideDocks"), false); | ||||
188 | | ||||
189 | if (_focusEditorOrHideDocks && _area != Qt::TopDockWidgetArea) { | ||||
190 | KConfigGroup config = KSharedConfig::openConfig()->group("UI"); | ||||
191 | bool defaultLockValue = (_area == Qt::LeftDockWidgetArea) ? true : false; | ||||
192 | setLocked(config.readEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(_area), defaultLockValue)); | ||||
193 | | ||||
194 | _lockButton = new LockButton(this); | ||||
195 | layout()->addWidget(_lockButton); | ||||
196 | } | ||||
125 | } | 197 | } | ||
126 | 198 | | |||
127 | QAction* IdealButtonBarWidget::addWidget(IdealDockWidget *dock, | 199 | QAction* IdealButtonBarWidget::addWidget(IdealDockWidget *dock, | ||
128 | Area *area, View *view) | 200 | Area *area, View *view) | ||
129 | { | 201 | { | ||
130 | if (_area == Qt::BottomDockWidgetArea || _area == Qt::TopDockWidgetArea) | 202 | if (_area == Qt::BottomDockWidgetArea || _area == Qt::TopDockWidgetArea) | ||
131 | dock->setFeatures( dock->features() | IdealDockWidget::DockWidgetVerticalTitleBar ); | 203 | dock->setFeatures( dock->features() | IdealDockWidget::DockWidgetVerticalTitleBar ); | ||
132 | 204 | | |||
Show All 39 Lines | 243 | { | |||
172 | _showState = isShown(); | 244 | _showState = isShown(); | ||
173 | } | 245 | } | ||
174 | 246 | | |||
175 | bool IdealButtonBarWidget::lastShowState() | 247 | bool IdealButtonBarWidget::lastShowState() | ||
176 | { | 248 | { | ||
177 | return _showState; | 249 | return _showState; | ||
178 | } | 250 | } | ||
179 | 251 | | |||
252 | bool IdealButtonBarWidget::isLocked() | ||||
253 | { | ||||
254 | return _isLocked; | ||||
255 | } | ||||
256 | | ||||
257 | void IdealButtonBarWidget::setLocked(bool lockValue) | ||||
258 | { | ||||
259 | _isLocked = lockValue; | ||||
260 | | ||||
261 | if (_lockButton) { | ||||
262 | KConfigGroup config = KSharedConfig::openConfig()->group("UI"); | ||||
263 | config.writeEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(_area), _isLocked); | ||||
264 | | ||||
265 | if (_lockButton->isLocked() != lockValue) | ||||
266 | _lockButton->setLocked(lockValue); | ||||
267 | } | ||||
268 | } | ||||
269 | | ||||
180 | Qt::Orientation IdealButtonBarWidget::orientation() const | 270 | Qt::Orientation IdealButtonBarWidget::orientation() const | ||
181 | { | 271 | { | ||
182 | if (_area == Qt::LeftDockWidgetArea || _area == Qt::RightDockWidgetArea) | 272 | if (_area == Qt::LeftDockWidgetArea || _area == Qt::RightDockWidgetArea) | ||
183 | return Qt::Vertical; | 273 | return Qt::Vertical; | ||
184 | 274 | | |||
185 | return Qt::Horizontal; | 275 | return Qt::Horizontal; | ||
186 | } | 276 | } | ||
187 | 277 | | |||
Show All 33 Lines | 300 | if (checked) { | |||
221 | } | 311 | } | ||
222 | 312 | | |||
223 | _controller->lastDockWidget[_area] = widgetAction->dockWidget(); | 313 | _controller->lastDockWidget[_area] = widgetAction->dockWidget(); | ||
224 | } | 314 | } | ||
225 | 315 | | |||
226 | _controller->showDockWidget(widgetAction->dockWidget(), checked); | 316 | _controller->showDockWidget(widgetAction->dockWidget(), checked); | ||
227 | widgetAction->setChecked(checked); | 317 | widgetAction->setChecked(checked); | ||
228 | button->setChecked(checked); | 318 | button->setChecked(checked); | ||
229 | } | | |||
230 | 319 | | |||
320 | if (_lockButton) | ||||
321 | _lockButton->setEnabled(isShown()); | ||||
322 | } | ||||
231 | 323 | | |||
232 | void IdealButtonBarWidget::actionEvent(QActionEvent *event) | 324 | void IdealButtonBarWidget::actionEvent(QActionEvent *event) | ||
233 | { | 325 | { | ||
234 | auto action = dynamic_cast<ToolViewAction *>(event->action()); | 326 | auto action = dynamic_cast<ToolViewAction *>(event->action()); | ||
235 | if (!action) | 327 | if (!action) | ||
236 | return; | 328 | return; | ||
237 | 329 | | |||
238 | switch (event->type()) { | 330 | switch (event->type()) { | ||
239 | case QEvent::ActionAdded: { | 331 | case QEvent::ActionAdded: { | ||
240 | bool wasEmpty = isEmpty(); | 332 | bool wasEmpty = isEmpty(); | ||
241 | if (!action->button()) { | 333 | if (!action->button()) { | ||
242 | IdealToolButton *button = new IdealToolButton(_area); | 334 | IdealToolButton *button = new IdealToolButton(_area); | ||
243 | //apol: here we set the usual width of a button for the vertical toolbars as the minimumWidth | 335 | //apol: here we set the usual width of a button for the vertical toolbars as the minimumWidth | ||
244 | //this is done because otherwise when we remove all the buttons and re-add new ones we get all | 336 | //this is done because otherwise when we remove all the buttons and re-add new ones we get all | ||
245 | //the screen flickering. This is solved by not defaulting to a smaller width when it's empty | 337 | //the screen flickering. This is solved by not defaulting to a smaller width when it's empty | ||
246 | int w = button->sizeHint().width(); | 338 | int w = button->sizeHint().width(); | ||
247 | if(orientation()==Qt::Vertical && w>minimumWidth()) | 339 | if(orientation()==Qt::Vertical && w>minimumWidth()) | ||
248 | setMinimumWidth(w); | 340 | setMinimumWidth(w); | ||
249 | action->setButton(button); | 341 | action->setButton(button); | ||
250 | button->setDefaultAction(action); | 342 | button->setDefaultAction(action); | ||
251 | 343 | | |||
252 | Q_ASSERT(action->dockWidget()); | 344 | Q_ASSERT(action->dockWidget()); | ||
253 | 345 | | |||
346 | if (_focusEditorOrHideDocks && _area == Qt::BottomDockWidgetArea) { | ||||
347 | layout()->replaceWidget(_lockButton, button); | ||||
348 | layout()->addWidget(_lockButton); | ||||
349 | } else | ||||
254 | layout()->addWidget(button); | 350 | layout()->addWidget(button); | ||
351 | | ||||
255 | connect(action, &QAction::toggled, this, static_cast<void(IdealButtonBarWidget::*)(bool)>(&IdealButtonBarWidget::showWidget)); | 352 | connect(action, &QAction::toggled, this, static_cast<void(IdealButtonBarWidget::*)(bool)>(&IdealButtonBarWidget::showWidget)); | ||
256 | connect(button, &IdealToolButton::clicked, this, &IdealButtonBarWidget::buttonPressed); | 353 | connect(button, &IdealToolButton::clicked, this, &IdealButtonBarWidget::buttonPressed); | ||
257 | connect(button, &IdealToolButton::customContextMenuRequested, | 354 | connect(button, &IdealToolButton::customContextMenuRequested, | ||
258 | action->dockWidget(), &IdealDockWidget::contextMenuRequested); | 355 | action->dockWidget(), &IdealDockWidget::contextMenuRequested); | ||
259 | if ( wasEmpty ) { | 356 | if ( wasEmpty ) { | ||
260 | emit emptyChanged(); | 357 | emit emptyChanged(); | ||
261 | } | 358 | } | ||
262 | } | 359 | } | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |