Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/sublime/idealbuttonbarwidget.cpp
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | |||||
100 | 100 | | |||
101 | IdealButtonBarWidget::IdealButtonBarWidget(Qt::DockWidgetArea area, | 101 | IdealButtonBarWidget::IdealButtonBarWidget(Qt::DockWidgetArea area, | ||
102 | IdealController *controller, Sublime::MainWindow *parent) | 102 | IdealController *controller, Sublime::MainWindow *parent) | ||
103 | : QWidget(parent) | 103 | : QWidget(parent) | ||
104 | , m_area(area) | 104 | , m_area(area) | ||
105 | , m_controller(controller) | 105 | , m_controller(controller) | ||
106 | , m_corner(nullptr) | 106 | , m_corner(nullptr) | ||
107 | , m_showState(false) | 107 | , m_showState(false) | ||
108 | , m_buttonsLayout(nullptr) | ||||
108 | { | 109 | { | ||
109 | setContextMenuPolicy(Qt::CustomContextMenu); | 110 | setContextMenuPolicy(Qt::CustomContextMenu); | ||
110 | setToolTip(i18nc("@info:tooltip", "Right click to add new tool views.")); | 111 | setToolTip(i18nc("@info:tooltip", "Right click to add new tool views.")); | ||
111 | 112 | | |||
112 | if (area == Qt::BottomDockWidgetArea) | 113 | if (area == Qt::BottomDockWidgetArea) | ||
113 | { | 114 | { | ||
114 | QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::RightToLeft, this); | 115 | QBoxLayout *statusLayout = new QBoxLayout(QBoxLayout::LeftToRight, this); | ||
115 | statusLayout->setMargin(0); | 116 | statusLayout->setMargin(0); | ||
116 | 117 | | |||
117 | IdealButtonBarLayout *l = new IdealButtonBarLayout(orientation()); | 118 | m_buttonsLayout = new IdealButtonBarLayout(orientation()); | ||
118 | statusLayout->addLayout(l); | 119 | statusLayout->addLayout(m_buttonsLayout); | ||
120 | | ||||
121 | statusLayout->addStretch(1); | ||||
119 | 122 | | |||
120 | m_corner = new QWidget(this); | 123 | m_corner = new QWidget(this); | ||
121 | QBoxLayout *cornerLayout = new QBoxLayout(QBoxLayout::LeftToRight, m_corner); | 124 | QBoxLayout *cornerLayout = new QBoxLayout(QBoxLayout::LeftToRight, m_corner); | ||
122 | cornerLayout->setMargin(0); | 125 | cornerLayout->setMargin(0); | ||
123 | cornerLayout->setSpacing(0); | 126 | cornerLayout->setSpacing(0); | ||
124 | statusLayout->addWidget(m_corner); | 127 | statusLayout->addWidget(m_corner); | ||
125 | statusLayout->addStretch(1); | | |||
126 | } | 128 | } | ||
127 | else | 129 | else | ||
128 | (void) new IdealButtonBarLayout(orientation(), this); | 130 | m_buttonsLayout = new IdealButtonBarLayout(orientation(), this); | ||
129 | } | 131 | } | ||
130 | 132 | | |||
131 | QAction* IdealButtonBarWidget::addWidget(IdealDockWidget *dock, | 133 | QAction* IdealButtonBarWidget::addWidget(IdealDockWidget *dock, | ||
132 | Area *area, View *view) | 134 | Area *area, View *view) | ||
133 | { | 135 | { | ||
134 | if (m_area == Qt::BottomDockWidgetArea || m_area == Qt::TopDockWidgetArea) | 136 | if (m_area == Qt::BottomDockWidgetArea || m_area == Qt::TopDockWidgetArea) | ||
135 | dock->setFeatures( dock->features() | IdealDockWidget::DockWidgetVerticalTitleBar ); | 137 | dock->setFeatures( dock->features() | IdealDockWidget::DockWidgetVerticalTitleBar ); | ||
136 | 138 | | |||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
189 | void IdealButtonBarWidget::removeAction(QAction* widgetAction) | 191 | void IdealButtonBarWidget::removeAction(QAction* widgetAction) | ||
190 | { | 192 | { | ||
191 | QWidget::removeAction(widgetAction); | 193 | QWidget::removeAction(widgetAction); | ||
192 | 194 | | |||
193 | auto action = static_cast<ToolViewAction*>(widgetAction); | 195 | auto action = static_cast<ToolViewAction*>(widgetAction); | ||
194 | action->button()->deleteLater(); | 196 | action->button()->deleteLater(); | ||
195 | delete action; | 197 | delete action; | ||
196 | 198 | | |||
197 | if (layout()->isEmpty()) { | 199 | if (m_buttonsLayout->isEmpty()) { | ||
198 | emit emptyChanged(); | 200 | emit emptyChanged(); | ||
199 | } | 201 | } | ||
200 | } | 202 | } | ||
201 | 203 | | |||
202 | bool IdealButtonBarWidget::isEmpty() const | 204 | bool IdealButtonBarWidget::isEmpty() const | ||
203 | { | 205 | { | ||
204 | return actions().isEmpty(); | 206 | return actions().isEmpty(); | ||
205 | } | 207 | } | ||
Show All 37 Lines | 239 | { | |||
243 | } | 245 | } | ||
244 | 246 | | |||
245 | return nullptr; | 247 | return nullptr; | ||
246 | } | 248 | } | ||
247 | 249 | | |||
248 | void IdealButtonBarWidget::addButtonToOrder(const IdealToolButton* button) | 250 | void IdealButtonBarWidget::addButtonToOrder(const IdealToolButton* button) | ||
249 | { | 251 | { | ||
250 | QString buttonId = id(button); | 252 | QString buttonId = id(button); | ||
251 | if (!m_buttonsOrder.contains(buttonId)) { | 253 | if (!m_buttonsOrder.contains(buttonId)) { | ||
252 | if (m_area == Qt::BottomDockWidgetArea) { | | |||
253 | m_buttonsOrder.push_front(buttonId); | | |||
254 | } | | |||
255 | else { | | |||
256 | m_buttonsOrder.push_back(buttonId); | 254 | m_buttonsOrder.push_back(buttonId); | ||
kossebau: Why did you remove the variant for the bottom docker? I have no idea why that exists :) but… | |||||
Previously, the buttons in the bottom dock were added to a RightToLeft Box Layout, now they're added to the IdealButtonBarLayout, which works from left to right. amhndu: Previously, the buttons in the bottom dock were added to a RightToLeft Box Layout, now they're… | |||||
Without it, new tools will be added to the far left of the bar, instead of the previous behavior of adding it to the right. amhndu: Without it, new tools will be added to the far left of the bar, instead of the previous… | |||||
257 | } | 255 | } | ||
258 | } | 256 | } | ||
259 | } | | |||
260 | 257 | | |||
261 | void IdealButtonBarWidget::loadOrderSettings(const KConfigGroup& configGroup) | 258 | void IdealButtonBarWidget::loadOrderSettings(const KConfigGroup& configGroup) | ||
262 | { | 259 | { | ||
263 | m_buttonsOrder = configGroup.readEntry(QStringLiteral("(%1) Tool Views Order").arg(m_area), QStringList()); | 260 | m_buttonsOrder = configGroup.readEntry(QStringLiteral("(%1) Tool Views Order").arg(m_area), QStringList()); | ||
264 | applyOrderToLayout(); | 261 | applyOrderToLayout(); | ||
265 | } | 262 | } | ||
266 | 263 | | |||
267 | void IdealButtonBarWidget::saveOrderSettings(KConfigGroup& configGroup) | 264 | void IdealButtonBarWidget::saveOrderSettings(KConfigGroup& configGroup) | ||
268 | { | 265 | { | ||
269 | takeOrderFromLayout(); | 266 | takeOrderFromLayout(); | ||
270 | configGroup.writeEntry(QStringLiteral("(%1) Tool Views Order").arg(m_area), m_buttonsOrder); | 267 | configGroup.writeEntry(QStringLiteral("(%1) Tool Views Order").arg(m_area), m_buttonsOrder); | ||
271 | } | 268 | } | ||
272 | 269 | | |||
273 | bool IdealButtonBarWidget::isLocked() const | 270 | bool IdealButtonBarWidget::isLocked() const | ||
274 | { | 271 | { | ||
275 | KConfigGroup config = KSharedConfig::openConfig()->group("UI"); | 272 | KConfigGroup config = KSharedConfig::openConfig()->group("UI"); | ||
276 | return config.readEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(m_area), false); | 273 | return config.readEntry(QStringLiteral("Toolview Bar (%1) Is Locked").arg(m_area), false); | ||
277 | } | 274 | } | ||
278 | 275 | | |||
279 | void IdealButtonBarWidget::applyOrderToLayout() | 276 | void IdealButtonBarWidget::applyOrderToLayout() | ||
280 | { | 277 | { | ||
281 | // If widget already have some buttons in the layout then calling loadOrderSettings() may leads | 278 | // If widget already have some buttons in the layout then calling loadOrderSettings() may leads | ||
282 | // to situations when loaded order does not contains all existing buttons. Therefore we should | 279 | // to situations when loaded order does not contains all existing buttons. Therefore we should | ||
283 | // fix this with using addToOrder() method. | 280 | // fix this with using addToOrder() method. | ||
284 | for (int i = 0; i < layout()->count(); ++i) { | 281 | for (int i = 0; i < m_buttonsLayout->count(); ++i) { | ||
285 | if (auto button = dynamic_cast<IdealToolButton*>(layout()->itemAt(i)->widget())) { | 282 | if (auto button = dynamic_cast<IdealToolButton*>(m_buttonsLayout->itemAt(i)->widget())) { | ||
286 | addButtonToOrder(button); | 283 | addButtonToOrder(button); | ||
287 | layout()->removeWidget(button); | 284 | m_buttonsLayout->removeWidget(button); | ||
288 | } | 285 | } | ||
289 | } | 286 | } | ||
290 | 287 | | |||
291 | foreach(const QString& id, m_buttonsOrder) { | 288 | foreach(const QString& id, m_buttonsOrder) { | ||
292 | if (auto b = button(id)) { | 289 | if (auto b = button(id)) { | ||
293 | layout()->addWidget(b); | 290 | m_buttonsLayout->addWidget(b); | ||
294 | } | 291 | } | ||
295 | } | 292 | } | ||
296 | } | 293 | } | ||
297 | 294 | | |||
298 | void IdealButtonBarWidget::takeOrderFromLayout() | 295 | void IdealButtonBarWidget::takeOrderFromLayout() | ||
299 | { | 296 | { | ||
300 | m_buttonsOrder.clear(); | 297 | m_buttonsOrder.clear(); | ||
301 | for (int i = 0; i < layout()->count(); ++i) { | 298 | for (int i = 0; i < m_buttonsLayout->count(); ++i) { | ||
302 | if (auto button = dynamic_cast<IdealToolButton*>(layout()->itemAt(i)->widget())) { | 299 | if (auto button = dynamic_cast<IdealToolButton*>(m_buttonsLayout->itemAt(i)->widget())) { | ||
303 | m_buttonsOrder += id(button); | 300 | m_buttonsOrder += id(button); | ||
304 | } | 301 | } | ||
305 | } | 302 | } | ||
306 | } | 303 | } | ||
307 | 304 | | |||
308 | Qt::Orientation IdealButtonBarWidget::orientation() const | 305 | Qt::Orientation IdealButtonBarWidget::orientation() const | ||
309 | { | 306 | { | ||
310 | if (m_area == Qt::LeftDockWidgetArea || m_area == Qt::RightDockWidgetArea) | 307 | if (m_area == Qt::LeftDockWidgetArea || m_area == Qt::RightDockWidgetArea) | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Why did you remove the variant for the bottom docker? I have no idea why that exists :) but then I also do not see why it should be removed, as it changes behaviour people have got used to, no?