1 /*******************************************************************************************************
2 DkTransferToolBar.cpp
3 Created on: 13.02.2012
4
5 nomacs is a fast and small image viewer with the capability of synchronizing multiple instances
6
7 Copyright (C) 2011-2013 Markus Diem <markus@nomacs.org>
8 Copyright (C) 2011-2013 Stefan Fiel <stefan@nomacs.org>
9 Copyright (C) 2011-2013 Florian Kleber <florian@nomacs.org>
10
11 This file is part of nomacs.
12
13 nomacs is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 nomacs is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 *******************************************************************************************************/
27
28 #include "DkToolbars.h"
29 #include "DkSettings.h"
30 #include "DkMath.h"
31 #include "DkUtils.h"
32 #include "DkImageStorage.h"
33 #include "DkQuickAccess.h"
34 #include "DkBasicWidgets.h"
35 #include "DkActionManager.h"
36
37 #include <assert.h>
38
39 #pragma warning(push, 0) // no warnings from includes - begin
40 #include <QToolBar>
41 #include <QWidget>
42 #include <QObject>
43 #include <QPainter>
44 #include <QLinearGradient>
45 #include <QImage>
46 #include <QPainterPath>
47 #include <QDebug>
48 #include <QMouseEvent>
49 #include <QColorDialog>
50 #include <QColor>
51 #include <QGradientStops>
52 #include <QPushButton>
53 #include <QComboBox>
54 #include <QLabel>
55 #include <QCheckBox>
56 #include <QHBoxLayout>
57 #include <QLayout>
58 #include <QIcon>
59 #include <QAction>
60 #include <QTranslator>
61 #include <QDoubleSpinBox>
62 #include <QMenu>
63 #include <QLineEdit>
64 #include <QCompleter>
65 //#include <QStringListModel>
66 #include <QStandardItemModel>
67 #include <QAbstractItemView>
68 #include <QMainWindow>
69
70 #include <QGridLayout>
71 #include <QGraphicsOpacityEffect>
72 #include <qmath.h>
73 #pragma warning(pop) // no warnings from includes - end
74
75 namespace nmc {
76
77 // DkMainToolBar --------------------------------------------------------------------
DkMainToolBar(const QString & title,QWidget * parent)78 DkMainToolBar::DkMainToolBar(const QString & title, QWidget * parent /* = 0 */) : QToolBar(title, parent) {
79
80 createLayout();
81 }
82
createLayout()83 void DkMainToolBar::createLayout() {
84
85 mQuickAccessEdit = new DkQuickAccessEdit(this);
86 }
87
setQuickAccessModel(QStandardItemModel * model)88 void DkMainToolBar::setQuickAccessModel(QStandardItemModel* model) {
89
90 mQuickAccessEdit->setModel(model);
91 addWidget(mQuickAccessEdit);
92 mQuickAccessEdit->setFocus(Qt::MouseFocusReason);
93 }
94
closeQuickAccess()95 void DkMainToolBar::closeQuickAccess() {
96
97 mQuickAccessEdit->clearAccess();
98 }
99
allActionsAdded()100 void DkMainToolBar::allActionsAdded() {
101
102 // right align search filters
103 QWidget* spacer = new QWidget(this);
104 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
105 addWidget(spacer);
106 //addWidget(quickFilterEdit);
107 }
108
getQuickAccess() const109 DkQuickAccessEdit* DkMainToolBar::getQuickAccess() const {
110 return mQuickAccessEdit;
111 }
112
113 // DkColorSlider:
DkColorSlider(QWidget * parent,qreal normedPos,QColor color,int sliderWidth)114 DkColorSlider::DkColorSlider(QWidget *parent, qreal normedPos, QColor color, int sliderWidth)
115 : DkWidget(parent) {
116
117 this->setStatusTip(tr("Drag the slider downwards for elimination"));
118 this->mNormedPos = normedPos;
119 this->mColor = color;
120 this->mSliderWidth = sliderWidth;
121 mIsActive = false;
122
123 mSliderHalfWidth = qCeil((float)sliderWidth / 2);
124 //return (qreal)(pos) / (qreal)(width() - sliderWidth);
125
126 int pos = qRound(normedPos * (parent->width() - sliderWidth - 1));
127
128 setGeometry(pos, 23, sliderWidth + 1, sliderWidth + mSliderHalfWidth + 1);
129
130 show();
131
132 }
133
paintEvent(QPaintEvent *)134 void DkColorSlider::paintEvent(QPaintEvent*) {
135
136 QPainter painter(this);
137
138 painter.setPen(Qt::black);
139
140 // Draw the filled triangle at the top of the slider:
141 if (mIsActive) {
142
143 QPainterPath path;
144 path.moveTo(0, mSliderHalfWidth);
145 path.lineTo(mSliderHalfWidth, 0);
146 path.lineTo(mSliderHalfWidth, 0);
147 path.lineTo(mSliderWidth, mSliderHalfWidth);
148
149 painter.fillPath(path, Qt::black);
150 painter.drawPath(path);
151
152 }
153 // Draw the empty triangle at the top of the slider:
154 else {
155 painter.drawLine(0, mSliderHalfWidth, mSliderHalfWidth, 0);
156 painter.drawLine(mSliderHalfWidth, 0, mSliderWidth, mSliderHalfWidth);
157 }
158
159 painter.drawRect(0, mSliderHalfWidth, mSliderWidth, mSliderWidth);
160 painter.fillRect(2, mSliderHalfWidth+2, mSliderWidth - 3, mSliderWidth - 3, mColor);
161
162
163 }
164
updatePos(int parentWidth)165 void DkColorSlider::updatePos(int parentWidth) {
166
167 int pos = qRound(mNormedPos * (parentWidth - mSliderWidth - 1));
168 setGeometry(pos, 23, mSliderWidth + 1, mSliderWidth + mSliderHalfWidth + 1);
169 }
170
setActive(bool isActive)171 void DkColorSlider::setActive(bool isActive) {
172
173 mIsActive = isActive;
174 }
175
~DkColorSlider()176 DkColorSlider::~DkColorSlider() {
177 }
178
getColor()179 QColor DkColorSlider::getColor() {
180
181 return mColor;
182 }
183
getNormedPos()184 qreal DkColorSlider::getNormedPos() {
185
186 return mNormedPos;
187 }
188
setNormedPos(qreal pos)189 void DkColorSlider::setNormedPos(qreal pos) {
190
191 mNormedPos = pos;
192 }
193
194
mousePressEvent(QMouseEvent * event)195 void DkColorSlider::mousePressEvent(QMouseEvent *event) {
196
197 mIsActive = true;
198 mDragStartX = event->pos().x();
199 emit sliderActivated(this);
200 }
201
mouseMoveEvent(QMouseEvent * event)202 void DkColorSlider::mouseMoveEvent(QMouseEvent *event) {
203
204 // Pass the actual position to the Gradient:
205 emit sliderMoved(this, event->pos().x() - mDragStartX, event->pos().y());
206
207 }
208
mouseDoubleClickEvent(QMouseEvent *)209 void DkColorSlider::mouseDoubleClickEvent(QMouseEvent*) {
210
211 QColor color = QColorDialog::getColor(this->mColor, this);
212 if (color.isValid())
213 this->mColor = color;
214
215 emit colorChanged(this);
216
217 }
218
DkGradient(QWidget * parent)219 DkGradient::DkGradient(QWidget *parent)
220 : DkWidget(parent) {
221
222 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
223
224 this->setMinimumWidth(100);
225 this->setMaximumWidth(600);
226
227 this->setFixedHeight(40);
228
229 mIsSliderDragged = false;
230 mClickAreaHeight = 20;
231 mDeleteSliderDist = 50;
232
233 // Note that sliderWidth should be odd, in order to get a pretty rendered slider.
234 mSliderWidth = 10;
235 mHalfSliderWidth = mSliderWidth / 2;
236 mGradient = QLinearGradient(0, 0, width(), height() - mClickAreaHeight);
237
238 mSliders = QVector<DkColorSlider*>();
239 init();
240
241 }
242
~DkGradient()243 DkGradient::~DkGradient() {
244 }
245
init()246 void DkGradient::init() {
247
248 clearAllSliders();
249
250 addSlider(0, Qt::black);
251 addSlider(1, Qt::white);
252
253 updateGradient();
254
255
256 }
257
clearAllSliders()258 void DkGradient::clearAllSliders() {
259
260 for (int i = 0; i < mSliders.size(); i++) {
261 DkColorSlider* slider = mSliders.at(i);
262 delete slider;
263 }
264
265 mSliders.clear();
266
267 }
268
setGradient(const QLinearGradient & gradient)269 void DkGradient::setGradient(const QLinearGradient& gradient) {
270
271 reset();
272 clearAllSliders(); // reset adds a slider at the start and end
273
274 this->mGradient.setStops(gradient.stops());
275
276 QVector<QGradientStop> stops = gradient.stops();
277
278 for (int idx = 0; idx < stops.size(); idx++) {
279 addSlider(stops.at(idx).first, stops.at(idx).second);
280 }
281
282 updateGradient();
283 update();
284 emit gradientChanged();
285
286 }
287
getGradient()288 QLinearGradient DkGradient::getGradient() {
289
290 return mGradient;
291 }
292
reset()293 void DkGradient::reset() {
294
295 init();
296 update();
297
298 }
299
300
resizeEvent(QResizeEvent * event)301 void DkGradient::resizeEvent( QResizeEvent * event ) {
302
303 if (event->size() == event->oldSize())
304 return;
305
306 DkColorSlider *slider;
307
308 for (int i = 0; i < mSliders.size(); i++) {
309 slider = mSliders.at(i);
310 slider->updatePos(this->width());
311 }
312
313 //qDebug() << "resize gradient: " << event->size();
314
315 updateGradient();
316
317 QWidget::resizeEvent(event);
318 }
319
320
addSlider(qreal pos,QColor color)321 void DkGradient::addSlider(qreal pos, QColor color) {
322
323
324 DkColorSlider *actSlider = new DkColorSlider(this, pos, color, mSliderWidth);
325 mSliders.append(actSlider);
326 connect(actSlider, SIGNAL(sliderMoved(DkColorSlider*, int, int)), this, SLOT(moveSlider(DkColorSlider*, int, int)));
327 connect(actSlider, SIGNAL(colorChanged(DkColorSlider*)), this, SLOT(changeColor(DkColorSlider*)));
328 connect(actSlider, SIGNAL(sliderActivated(DkColorSlider*)), this, SLOT(activateSlider(DkColorSlider*)));
329
330 }
331
insertSlider(qreal pos,QColor col)332 void DkGradient::insertSlider(qreal pos, QColor col) {
333
334 // Inserts a new slider at position pos and calculates the color, interpolated from the closest neighbors.
335
336 // Find the neighbors of the new slider, since we need it for the color interpolation:
337 QColor leftColor, rightColor, actColor;
338 qreal dist;
339 qreal initValue = DBL_MAX; //std::numeric_limits<qreal>::max(); // >DIR: fix for linux [9.2.2012 markus]
340 qreal leftDist = initValue;
341 qreal rightDist = initValue;
342
343 int leftIdx = 0, rightIdx = 0;
344
345 for (int i = 0; i < mSliders.size(); i++) {
346 dist = mSliders.at(i)->getNormedPos() - pos;
347 if (dist < 0) {
348 if (std::abs(dist) < leftDist) {
349 leftDist = (std::abs(dist));
350 leftIdx = i;
351 }
352 }
353 else if (dist > 0){
354 if (std::abs(dist) < rightDist) {
355 rightDist = (std::abs(dist));
356 rightIdx = i;
357 }
358 }
359 else {
360 actColor = mSliders.at(i)->getColor();
361 break;
362 }
363 }
364
365 if ((leftDist == initValue) && (rightDist == initValue))
366 actColor = Qt::black;
367 // The slider is most left:
368 else if (leftDist == initValue)
369 actColor = mSliders.at(rightIdx)->getColor();
370 // The slider is most right:
371 else if (rightDist == initValue)
372 actColor = mSliders.at(leftIdx)->getColor();
373 // The slider has a neighbor to the left and to the right:
374 else {
375 int rLeft, rRight, rNew, gLeft, gRight, gNew, bLeft, bRight, bNew;
376
377 mSliders.at(leftIdx)->getColor().getRgb(&rLeft, &gLeft, &bLeft);
378 mSliders.at(rightIdx)->getColor().getRgb(&rRight, &gRight, &bRight);
379
380 qreal fac = leftDist / (leftDist + rightDist);
381 rNew = qRound(rLeft * (1 - fac) + rRight * fac);
382 gNew = qRound(gLeft * (1 - fac) + gRight * fac);
383 bNew = qRound(bLeft * (1 - fac) + bRight * fac);
384
385 actColor = QColor(rNew, gNew, bNew);
386
387 }
388
389
390 addSlider(pos, col.isValid() ? col : actColor);
391 // The last slider in the list is the last one added, now make this one active:
392 activateSlider(mSliders.last());
393
394 updateGradient();
395 update();
396
397
398 }
399
mousePressEvent(QMouseEvent * event)400 void DkGradient::mousePressEvent(QMouseEvent *event) {
401
402 QPointF enterPos = event->pos();
403 qreal pos = (qreal)(enterPos.x() - mHalfSliderWidth) / (qreal)(width()-mSliderWidth);
404
405 insertSlider(pos);
406
407 }
408
updateGradient()409 void DkGradient::updateGradient() {
410
411 mGradient = QLinearGradient(0, 0, width(), height() - mClickAreaHeight);
412
413 for (int i = 0; i < mSliders.size(); i++)
414 mGradient.setColorAt(mSliders.at(i)->getNormedPos(), mSliders.at(i)->getColor());
415
416 }
417
getGradientStops()418 QGradientStops DkGradient::getGradientStops() {
419
420 return mGradient.stops();
421 }
422
moveSlider(DkColorSlider * sender,int dragDistX,int yPos)423 void DkGradient::moveSlider(DkColorSlider* sender, int dragDistX, int yPos) {
424
425
426 // Delete the actual slider:
427 if (yPos > mDeleteSliderDist) {
428 int idx = mSliders.lastIndexOf(sender);
429 if (idx != -1) {
430 mSliders.remove(idx);
431 delete sender;
432 mIsActiveSliderExisting = false;
433 }
434 }
435
436 // Insert a new slider:
437 else {
438
439 int newPos = sender->pos().x() + dragDistX;
440
441 if (newPos < 0)
442 newPos = 0;
443 else if (newPos > width() - mSliderWidth - 1)
444 newPos = width() - mSliderWidth - 1;
445
446 qreal normedSliderPos = getNormedPos(newPos);
447
448 if (normedSliderPos > 1)
449 normedSliderPos = 1;
450 if (normedSliderPos < 0)
451 normedSliderPos = 0;
452
453 DkColorSlider *slider;
454 // Check if the position is already assigned to another slider:
455 for (int i = 0; i < mSliders.size(); i++) {
456 slider = mSliders.at(i);
457 if (slider != sender) {
458 if (slider->getNormedPos() == normedSliderPos)
459 return;
460 }
461 }
462
463 sender->setNormedPos(normedSliderPos);
464 sender->move(newPos, sender->pos().y());
465
466 }
467
468 updateGradient();
469 update();
470
471 emit gradientChanged();
472
473 }
474
getNormedPos(int pos)475 qreal DkGradient::getNormedPos(int pos) {
476
477 return (qreal)(pos) / (qreal)(width() - mSliderWidth);
478
479 }
480
getAbsolutePos(qreal pos)481 int DkGradient::getAbsolutePos(qreal pos) {
482
483 return (int) pos * width();
484
485 }
486
paintEvent(QPaintEvent *)487 void DkGradient::paintEvent(QPaintEvent*) {
488
489 QPainter painter(this);
490 painter.setPen(Qt::gray);
491
492 painter.fillRect(mHalfSliderWidth, 2, width() - mSliderWidth, height() - mClickAreaHeight, mGradient);
493 painter.drawRect(mHalfSliderWidth, 2, width() - mSliderWidth, height() - mClickAreaHeight);
494 }
495
496
mouseReleaseEvent(QMouseEvent *)497 void DkGradient::mouseReleaseEvent(QMouseEvent *) {
498
499 // unused
500 }
501
changeColor(DkColorSlider *)502 void DkGradient::changeColor(DkColorSlider*) {
503
504 updateGradient();
505 update();
506
507 emit gradientChanged();
508 }
509
activateSlider(DkColorSlider * sender)510 void DkGradient::activateSlider(DkColorSlider *sender) {
511
512
513 if (mIsActiveSliderExisting)
514 mActiveSlider->setActive(false);
515 else
516 mIsActiveSliderExisting = true;
517
518 mActiveSlider = sender;
519 mActiveSlider->setActive(true);
520
521 update();
522
523 }
524
525 //
DkTransferToolBar(QWidget * parent)526 DkTransferToolBar::DkTransferToolBar(QWidget * parent)
527 : QToolBar(tr("Pseudo Color Toolbar"), parent) {
528
529 loadSettings();
530
531
532 mEnableTFCheckBox = new QCheckBox(tr("Enable"));
533 mEnableTFCheckBox->setStatusTip(tr("Enables the Pseudo Color function"));
534
535 this->addWidget(mEnableTFCheckBox);
536
537 // >DIR: more compact gui [2.3.2012 markus]
538 this->addSeparator();
539 //this->addWidget(new QLabel(tr("Active channel:")));
540
541 mChannelComboBox = new QComboBox(this);
542 mChannelComboBox->setStatusTip(tr("Changes the displayed color channel"));
543 this->addWidget(mChannelComboBox);
544
545 mHistoryCombo = new QComboBox(this);
546
547 QAction* delGradientAction = new QAction(tr("Delete"), mHistoryCombo);
548 connect(delGradientAction, SIGNAL(triggered()), this, SLOT(deleteGradient()));
549
550 mHistoryCombo->addAction(delGradientAction);
551 mHistoryCombo->setContextMenuPolicy(Qt::ActionsContextMenu);
552
553 updateGradientHistory();
554 connect(mHistoryCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(switchGradient(int)));
555 connect(mHistoryCombo, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(deleteGradientMenu(QPoint)));
556
557 this->addWidget(mHistoryCombo);
558
559 createIcons();
560
561 mGradient = new DkGradient(this);
562 mGradient->setStatusTip(tr("Click into the field for a new slider"));
563 this->addWidget(mGradient);
564
565 mEffect = new QGraphicsOpacityEffect(mGradient);
566 mEffect->setOpacity(1);
567 mGradient->setGraphicsEffect(mEffect);
568
569 // Disable the entire transfer toolbar:
570 //enableTF(Qt::Unchecked);
571
572 // Initialize the combo box for color images:
573 mImageMode = mode_uninitialized;
574 applyImageMode(mode_rgb);
575
576 enableToolBar(false);
577 mEnableTFCheckBox->setEnabled(true);
578
579 connect(mEnableTFCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableTFCheckBoxClicked(int)));
580 connect(mGradient, SIGNAL(gradientChanged()), this, SLOT(applyTF()));
581
582 // needed for initialization
583 connect(this, SIGNAL(gradientChanged()), mGradient, SIGNAL(gradientChanged()));
584
585 if (!mOldGradients.empty())
586 mGradient->setGradient(mOldGradients.first());
587
588 }
589
~DkTransferToolBar()590 DkTransferToolBar::~DkTransferToolBar() {
591 }
592
593
createIcons()594 void DkTransferToolBar::createIcons() {
595
596 // user needs to decide...
597 //this->setIconSize(QSize(DkSettingsManager::param().effectiveIconSize(), DkSettingsManager::param().effectiveIconSize()));
598
599 mToolBarIcons.resize(icon_toolbar_end);
600
601 mToolBarIcons[icon_toolbar_reset] = DkImage::loadIcon(":/nomacs/img/gradient-reset.svg");
602 mToolBarIcons[icon_toolbar_pipette] = DkImage::loadIcon(":/nomacs/img/pipette.svg");
603 mToolBarIcons[icon_toolbar_save] = DkImage::loadIcon(":/nomacs/img/save.svg");
604
605 mToolBarActions.resize(toolbar_end);
606 mToolBarActions[toolbar_reset] = new QAction(mToolBarIcons[icon_toolbar_reset], tr("Reset"), this);
607 mToolBarActions[toolbar_reset]->setStatusTip(tr("Resets the Pseudo Color function"));
608 connect(mToolBarActions[toolbar_reset], SIGNAL(triggered()), this, SLOT(resetGradient()));
609
610 //toolBarActions[toolbar_reset]->setToolTip("was geht?");
611
612 mToolBarActions[toolbar_pipette] = new QAction(mToolBarIcons[icon_toolbar_pipette], tr("Select Color"), this);
613 mToolBarActions[toolbar_pipette]->setStatusTip(tr("Adds a slider at the selected color value"));
614 mToolBarActions[toolbar_pipette]->setCheckable(true);
615 mToolBarActions[toolbar_pipette]->setChecked(false);
616 connect(mToolBarActions[toolbar_pipette], SIGNAL(triggered(bool)), this, SLOT(pickColor(bool)));
617
618 mToolBarActions[toolbar_save] = new QAction(mToolBarIcons[icon_toolbar_save], tr("Save Gradient"), this);
619 mToolBarActions[toolbar_save]->setStatusTip(tr("Saves the current Gradient"));
620 connect(mToolBarActions[toolbar_save], SIGNAL(triggered()), this, SLOT(saveGradient()));
621
622 addActions(mToolBarActions.toList());
623
624 }
625
saveSettings()626 void DkTransferToolBar::saveSettings() {
627
628 DefaultSettings settings;
629 settings.beginGroup("Pseudo Color");
630
631 settings.beginWriteArray("oldGradients", mOldGradients.size());
632
633 for (int idx = 0; idx < mOldGradients.size(); idx++) {
634 settings.setArrayIndex(idx);
635
636 QVector<QGradientStop> stops = mOldGradients.at(idx).stops();
637 settings.beginWriteArray("gradient", stops.size());
638
639 for (int sIdx = 0; sIdx < stops.size(); sIdx++) {
640 settings.setArrayIndex(sIdx);
641 settings.setValue("posRGBA", (float)stops.at(sIdx).first);
642 settings.setValue("colorRGBA", stops.at(sIdx).second.rgba());
643 }
644 settings.endArray();
645 }
646
647 settings.endArray();
648 settings.endGroup();
649 }
650
loadSettings()651 void DkTransferToolBar::loadSettings() {
652
653 DefaultSettings settings;
654 settings.beginGroup("Pseudo Color");
655
656 int gSize = settings.beginReadArray("oldGradients");
657
658 for (int idx = 0; idx < gSize; idx++) {
659 settings.setArrayIndex(idx);
660
661 QVector<QGradientStop> stops;
662 int sSize = settings.beginReadArray("gradient");
663
664 for (int sIdx = 0; sIdx < sSize; sIdx++) {
665 settings.setArrayIndex(sIdx);
666
667 QGradientStop s;
668 s.first = settings.value("posRGBA", 0).toFloat();
669 s.second = QColor::fromRgba(settings.value("colorRGBA", QColor().rgba()).toInt());
670 qDebug() << "pos: " << s.first << " col: " << s.second;
671 stops.append(s);
672 }
673 settings.endArray();
674
675 QLinearGradient g;
676 g.setStops(stops);
677 mOldGradients.append(g);
678 }
679
680 settings.endArray();
681 settings.endGroup();
682 }
683
deleteGradientMenu(QPoint pos)684 void DkTransferToolBar::deleteGradientMenu(QPoint pos) {
685
686 QMenu* cm = new QMenu(this);
687 QAction* delAction = new QAction("Delete", this);
688 connect(delAction, SIGNAL(triggered()), this, SLOT(deleteGradient()));
689 cm->popup(mHistoryCombo->mapToGlobal(pos));
690 cm->exec();
691 }
692
deleteGradient()693 void DkTransferToolBar::deleteGradient() {
694
695 int idx = mHistoryCombo->currentIndex();
696
697 if (idx >= 0 && idx < mOldGradients.size()) {
698 mOldGradients.remove(idx);
699 mHistoryCombo->removeItem(idx);
700 }
701
702 }
703
resizeEvent(QResizeEvent * event)704 void DkTransferToolBar::resizeEvent( QResizeEvent * event ) {
705
706 mGradient->resize(event->size().width() - mGradient->x(), 40);
707
708 }
709
insertSlider(qreal pos)710 void DkTransferToolBar::insertSlider(qreal pos) {
711
712 mGradient->insertSlider(pos);
713
714 }
715
setImageMode(int mode)716 void DkTransferToolBar::setImageMode(int mode) {
717
718 qDebug() << "and I received...";
719 applyImageMode(mode);
720
721 }
722
applyImageMode(int mode)723 void DkTransferToolBar::applyImageMode(int mode) {
724
725 // At first check if the right mode is already set. If so, don't do nothing.
726
727 if (mode == mImageMode)
728 return;
729
730 //if (mImageMode != mode_invalid_format) {
731 // enableToolBar(true);
732 // emit channelChanged(0);
733 //}
734
735 mImageMode = mode;
736 mEnableTFCheckBox->setEnabled(mImageMode != mode_invalid_format);
737
738 if (mImageMode == mode_invalid_format) {
739 enableToolBar(false);
740 return;
741 }
742
743 disconnect(mChannelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeChannel(int)));
744 mChannelComboBox->clear();
745
746 if (mode == mode_gray) {
747 mChannelComboBox->addItem(tr("Gray"));
748 }
749 else if (mode == mode_rgb) {
750 mChannelComboBox->addItem(tr("RGB"));
751 mChannelComboBox->addItem(tr("Red"));
752 mChannelComboBox->addItem(tr("Green"));
753 mChannelComboBox->addItem(tr("Blue"));
754 }
755
756 mChannelComboBox->setCurrentIndex(0);
757
758 connect(mChannelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeChannel(int)));
759
760 }
761
pickColor(bool enabled)762 void DkTransferToolBar::pickColor(bool enabled) {
763
764 emit pickColorRequest(enabled);
765 }
766
enableTFCheckBoxClicked(int state)767 void DkTransferToolBar::enableTFCheckBoxClicked(int state) {
768
769 bool enabled;
770 if (state == Qt::Checked)
771 enabled = true;
772 else
773 enabled = false;
774
775 enableToolBar(enabled);
776
777 // At this point the checkbox is disabled, hence enable it...
778 mEnableTFCheckBox->setEnabled(true);
779
780 if (enabled)
781 mEnableTFCheckBox->setStatusTip(tr("Disables the Pseudo Color function"));
782 else
783 mEnableTFCheckBox->setStatusTip(tr("Enables the Pseudo Color function"));
784
785 emit tFEnabled(enabled);
786 emit gradientChanged();
787 }
788
enableToolBar(bool enable)789 void DkTransferToolBar::enableToolBar(bool enable) {
790
791 QObjectList list = this->children();
792
793 for (int i = 0; i < list.count(); i++) {
794 if (QWidget *action = qobject_cast<QWidget*>(list.at(i)))
795 action->setEnabled(enable);
796 }
797
798 if (enable)
799 mEffect->setOpacity(1);
800 else
801 mEffect->setOpacity(.5);
802
803 }
804
applyTF()805 void DkTransferToolBar::applyTF() {
806
807 QGradientStops stops = mGradient->getGradientStops();
808
809 emit colorTableChanged(stops);
810 }
811
changeChannel(int index)812 void DkTransferToolBar::changeChannel(int index) {
813
814 emit channelChanged(index);
815 }
816
resetGradient()817 void DkTransferToolBar::resetGradient() {
818
819 mGradient->reset();
820
821 QGradientStops stops = mGradient->getGradientStops();
822
823 emit colorTableChanged(stops);
824 }
825
paintEvent(QPaintEvent * event)826 void DkTransferToolBar::paintEvent(QPaintEvent* event) {
827
828 QToolBar::paintEvent(event);
829
830 }
831
updateGradientHistory()832 void DkTransferToolBar::updateGradientHistory() {
833
834 mHistoryCombo->clear();
835 mHistoryCombo->setIconSize(QSize(50,10));
836
837 for (int idx = 0; idx < mOldGradients.size(); idx++) {
838
839 QPixmap cg(50, 10);
840 QLinearGradient g(QPoint(0,0), QPoint(50, 0));
841 g.setStops(mOldGradients[idx].stops());
842 QPainter p(&cg);
843 p.fillRect(cg.rect(), g);
844 mHistoryCombo->addItem(cg, tr(""));
845 }
846 }
847
switchGradient(int idx)848 void DkTransferToolBar::switchGradient(int idx) {
849
850 if (idx >= 0 && idx < mOldGradients.size()) {
851 mGradient->setGradient(mOldGradients[idx]);
852 }
853
854 }
855
saveGradient()856 void DkTransferToolBar::saveGradient() {
857
858 mOldGradients.prepend(mGradient->getGradient());
859 updateGradientHistory();
860 saveSettings();
861 }
862
863 // DkCropToolbar --------------------------------------------------------------------
DkCropToolBar(const QString & title,QWidget * parent)864 DkCropToolBar::DkCropToolBar(const QString & title, QWidget * parent /* = 0 */) : QToolBar(title, parent) {
865
866 createIcons();
867 createLayout();
868 QMetaObject::connectSlotsByName(this);
869
870 setIconSize(QSize(DkSettingsManager::param().effectiveIconSize(this), DkSettingsManager::param().effectiveIconSize(this)));
871 setObjectName("cropToolBar");
872 }
873
~DkCropToolBar()874 DkCropToolBar::~DkCropToolBar() {
875
876 // save settings
877 saveSettings();
878 }
879
loadSettings()880 void DkCropToolBar::loadSettings() {
881
882 DefaultSettings settings;
883 settings.beginGroup("Crop");
884
885 mHorValBox->setValue(settings.value("AspectRatioHorizontal", 0).toInt());
886 mVerValBox->setValue(settings.value("AspectRatioVertical", 0).toInt());
887 mGuideBox->setCurrentIndex(settings.value("guides", 1).toInt());
888 mInvertAction->setChecked(settings.value("inverted", false).toBool());
889 mInfoAction->setChecked(settings.value("info", true).toBool());
890 mCbMeta->setChecked(settings.value("cropToMetadata", false).toBool());
891 settings.endGroup();
892 }
893
saveSettings()894 void DkCropToolBar::saveSettings() {
895
896 DefaultSettings settings;
897 settings.beginGroup("Crop");
898
899 settings.setValue("AspectRatioHorizontal", mHorValBox->value());
900 settings.setValue("AspectRatioVertical", mVerValBox->value());
901 settings.setValue("guides", mGuideBox->currentIndex());
902 settings.setValue("inverted", mInvertAction->isChecked());
903 settings.setValue("info", mInfoAction->isChecked());
904 settings.setValue("cropToMetadata", mCbMeta->isChecked());
905 settings.endGroup();
906 }
907
createIcons()908 void DkCropToolBar::createIcons() {
909
910 // create icons
911 mIcons.resize(icons_end);
912
913 mIcons[crop_icon] = DkImage::loadIcon(":/nomacs/img/crop.svg");
914 mIcons[cancel_icon] = DkImage::loadIcon(":/nomacs/img/close.svg");
915 mIcons[pan_icon] = DkImage::loadIcon(":/nomacs/img/pan.svg");
916 mIcons[pan_icon].addPixmap(DkImage::loadIcon(":/nomacs/img/pan-checked.svg"), QIcon::Normal, QIcon::On);
917 mIcons[invert_icon] = DkImage::loadIcon(":/nomacs/img/crop-invert.svg");
918 mIcons[invert_icon].addPixmap(DkImage::loadIcon(":/nomacs/img/crop-invert-checked.svg"), QIcon::Normal, QIcon::On);
919 mIcons[info_icon] = DkImage::loadIcon(":/nomacs/img/info.svg");
920
921 if (!DkSettingsManager::param().display().defaultIconColor) {
922 // now colorize all icons
923 for (int idx = 0; idx < mIcons.size(); idx++) {
924
925 mIcons[idx].addPixmap(DkImage::colorizePixmap(mIcons[idx].pixmap(DkSettingsManager::param().effectiveIconSize(this), QIcon::Normal, QIcon::On), DkSettingsManager::param().display().iconColor), QIcon::Normal, QIcon::On);
926 mIcons[idx].addPixmap(DkImage::colorizePixmap(mIcons[idx].pixmap(DkSettingsManager::param().effectiveIconSize(this), QIcon::Normal, QIcon::Off), DkSettingsManager::param().display().iconColor), QIcon::Normal, QIcon::Off);
927 }
928 }
929 }
930
createLayout()931 void DkCropToolBar::createLayout() {
932
933 QList<QKeySequence> enterSc;
934 enterSc.append(QKeySequence(Qt::Key_Enter));
935 enterSc.append(QKeySequence(Qt::Key_Return));
936
937 QAction* cropAction = new QAction(mIcons[crop_icon], tr("Crop (ENTER)"), this);
938 cropAction->setShortcuts(enterSc);
939 cropAction->setObjectName("cropAction");
940
941 QAction* cancelAction = new QAction(mIcons[cancel_icon], tr("Cancel (ESC)"), this);
942 cancelAction->setShortcut(QKeySequence(Qt::Key_Escape));
943 cancelAction->setObjectName("cancelAction");
944
945 mPanAction = new QAction(mIcons[pan_icon], tr("Pan"), this);
946 mPanAction->setShortcut(QKeySequence(Qt::Key_P));
947 mPanAction->setObjectName("panAction");
948 mPanAction->setCheckable(true);
949 mPanAction->setChecked(false);
950
951 QStringList ratios;
952 ratios << "1:1" << "4:3" << "5:4" << "14:10" << "14:11" << "16:9" << "16:10";
953 ratios.prepend(tr("User Defined"));
954 ratios.prepend(tr("No Aspect Ratio"));
955 mRatioBox = new QComboBox(this);
956 mRatioBox->addItems(ratios);
957 mRatioBox->setObjectName("ratioBox");
958
959 mHorValBox = new QDoubleSpinBox(this);
960 mHorValBox->setObjectName("horValBox");
961 mHorValBox->setSpecialValueText(" ");
962 mHorValBox->setToolTip(tr("Horizontal Constraint"));
963 mHorValBox->setStatusTip(mHorValBox->toolTip());
964
965 QAction* swapAction = new QAction(DkImage::loadIcon(":/nomacs/img/swap.svg"), tr("Swap"), this);
966 swapAction->setObjectName("swapAction");
967 swapAction->setToolTip(tr("Swap Dimensions"));
968 swapAction->setStatusTip(swapAction->toolTip());
969
970 mVerValBox = new QDoubleSpinBox(this);
971 mVerValBox->setObjectName("verValBox");
972 mVerValBox->setSpecialValueText(" ");
973 mHorValBox->setToolTip(tr("Vertical Constraint"));
974 mHorValBox->setStatusTip(mHorValBox->toolTip());
975
976 mAngleBox = new QDoubleSpinBox(this);
977 mAngleBox->setObjectName("angleBox");
978 mAngleBox->setSuffix(dk_degree_str);
979 mAngleBox->setMinimum(-180);
980 mAngleBox->setMaximum(180);
981
982 // background color
983 mBgCol = QColor(0,0,0,0);
984 mBgColButton = new QPushButton(this);
985 mBgColButton->setObjectName("bgColButton");
986 mBgColButton->setStyleSheet("QPushButton {background-color: " + DkUtils::colorToString(mBgCol) + "; border: 1px solid #888;}");
987 mBgColButton->setToolTip(tr("Background Color"));
988 mBgColButton->setStatusTip(mBgColButton->toolTip());
989
990 mColorDialog = new QColorDialog(this);
991 mColorDialog->setObjectName("colorDialog");
992 mColorDialog->setOption(QColorDialog::ShowAlphaChannel, true);
993
994 // crop customization
995 QStringList guides;
996 guides << tr("Guides") << tr("Rule of Thirds") << tr("Grid");
997 mGuideBox = new QComboBox(this);
998 mGuideBox->addItems(guides);
999 mGuideBox->setObjectName("guideBox");
1000 mGuideBox->setToolTip(tr("Show Guides in the Preview"));
1001 mGuideBox->setStatusTip(mGuideBox->toolTip());
1002
1003 mInvertAction = new QAction(mIcons[invert_icon], tr("Invert Crop Tool Color"), this);
1004 mInvertAction->setObjectName("invertAction");
1005 mInvertAction->setCheckable(true);
1006 mInvertAction->setChecked(false);
1007
1008 mInfoAction = new QAction(mIcons[info_icon], tr("Show Info"), this);
1009 mInfoAction->setObjectName("infoAction");
1010 mInfoAction->setCheckable(true);
1011 mInfoAction->setChecked(false);
1012
1013 mCbMeta = new QCheckBox(tr("Crop to Metadata"), this);
1014 mCbMeta->setChecked(false);
1015 mCbMeta->hide(); // "disabled" for now (keep it simple)
1016
1017 mCropRect = new DkRectWidget(QRect(), this);
1018 mCropRect->setObjectName("cropRect");
1019
1020 addAction(cropAction);
1021 addAction(mPanAction);
1022 addAction(cancelAction);
1023 addSeparator();
1024 addWidget(mRatioBox);
1025 addWidget(mHorValBox);
1026 addAction(swapAction);
1027 addWidget(mVerValBox);
1028 addWidget(mAngleBox);
1029 addSeparator();
1030 addWidget(mBgColButton);
1031 addSeparator();
1032 addWidget(mGuideBox);
1033 addAction(mInvertAction);
1034 addAction(mInfoAction);
1035 addWidget(mCbMeta);
1036 addSeparator();
1037 addWidget(mCropRect);
1038
1039 connect(mCropRect, SIGNAL(updateRectSignal(const QRect&)), this, SIGNAL(updateRectSignal(const QRect&)));
1040 }
1041
setVisible(bool visible)1042 void DkCropToolBar::setVisible(bool visible) {
1043
1044 if (!visible)
1045 emit colorSignal(Qt::NoBrush);
1046 else
1047 emit colorSignal(mBgCol);
1048
1049 if (visible) {
1050 mPanAction->setChecked(false);
1051 mAngleBox->setValue(0);
1052 }
1053
1054 QToolBar::setVisible(visible);
1055 }
1056
setAspectRatio(const QPointF & aRatio)1057 void DkCropToolBar::setAspectRatio(const QPointF& aRatio) {
1058
1059 mHorValBox->setValue(aRatio.x());
1060 mVerValBox->setValue(aRatio.y());
1061 }
1062
setRect(const QRect & r)1063 void DkCropToolBar::setRect(const QRect & r) {
1064 mCropRect->setRect(r);
1065 }
1066
on_cropAction_triggered()1067 void DkCropToolBar::on_cropAction_triggered() {
1068 emit cropSignal(mCbMeta->isChecked());
1069 }
1070
on_cancelAction_triggered()1071 void DkCropToolBar::on_cancelAction_triggered() {
1072 emit cancelSignal();
1073 }
1074
on_invertAction_toggled(bool checked)1075 void DkCropToolBar::on_invertAction_toggled(bool checked) {
1076 emit shadingHint(checked);
1077 }
1078
on_infoAction_toggled(bool checked)1079 void DkCropToolBar::on_infoAction_toggled(bool checked) {
1080 emit showInfo(checked);
1081 }
1082
on_swapAction_triggered()1083 void DkCropToolBar::on_swapAction_triggered() {
1084
1085 int tmpV = qRound(mHorValBox->value());
1086 mHorValBox->setValue(mVerValBox->value());
1087 mVerValBox->setValue(tmpV);
1088
1089 }
1090
on_angleBox_valueChanged(double val)1091 void DkCropToolBar::on_angleBox_valueChanged(double val) {
1092
1093 emit angleSignal(DK_DEG2RAD*val);
1094 }
1095
angleChanged(double val)1096 void DkCropToolBar::angleChanged(double val) {
1097
1098 double angle = val*DK_RAD2DEG;
1099 while (angle > 90)
1100 angle -= 180;
1101 while (angle <= -90)
1102 angle += 180;
1103
1104 mAngleBox->blockSignals(true);
1105 mAngleBox->setValue(angle);
1106 mAngleBox->blockSignals(false);
1107 }
1108
on_bgColButton_clicked()1109 void DkCropToolBar::on_bgColButton_clicked() {
1110
1111 QColor tmpCol = mBgCol;
1112 if (!tmpCol.alpha()) tmpCol.setAlpha(255); // avoid frustrated users
1113
1114 mColorDialog->setCurrentColor(tmpCol);
1115 int ok = mColorDialog->exec();
1116
1117 if (ok == QDialog::Accepted) {
1118 mBgCol = mColorDialog->currentColor();
1119 mBgColButton->setStyleSheet("QPushButton {background-color: " + DkUtils::colorToString(mBgCol) + "; border: 1px solid #888;}");
1120 emit colorSignal(mBgCol);
1121 }
1122
1123 }
1124
1125
on_ratioBox_currentIndexChanged(const QString & text)1126 void DkCropToolBar::on_ratioBox_currentIndexChanged(const QString& text) {
1127
1128 // user defined -> do nothing
1129 if (mRatioBox->currentIndex() == 1)
1130 return;
1131
1132 // no aspect ratio -> clear boxes
1133 if (mRatioBox->currentIndex() == 0) {
1134 mHorValBox->setValue(0);
1135 mVerValBox->setValue(0);
1136 return;
1137 }
1138
1139 QStringList vals = text.split(":");
1140
1141 qDebug() << vals;
1142
1143 if (vals.size() == 2) {
1144 mHorValBox->setValue(vals[0].toDouble());
1145 mVerValBox->setValue(vals[1].toDouble());
1146 }
1147 }
1148
on_guideBox_currentIndexChanged(int idx)1149 void DkCropToolBar::on_guideBox_currentIndexChanged(int idx) {
1150
1151 emit paintHint(idx);
1152 }
1153
on_verValBox_valueChanged(double val)1154 void DkCropToolBar::on_verValBox_valueChanged(double val) {
1155
1156 // just pass it on
1157 on_horValBox_valueChanged(val);
1158 }
1159
on_horValBox_valueChanged(double)1160 void DkCropToolBar::on_horValBox_valueChanged(double) {
1161
1162 DkVector diag = DkVector((float)mHorValBox->value(), (float)mVerValBox->value());
1163 emit aspectRatio(diag);
1164
1165 QString rs = QString::number(mHorValBox->value()) + ":" + QString::number(mVerValBox->value());
1166
1167 int idx = mRatioBox->findText(rs);
1168
1169 if (idx != -1)
1170 mRatioBox->setCurrentIndex(idx);
1171 else if (mHorValBox->value() == 0 && mVerValBox->value() == 0)
1172 mRatioBox->setCurrentIndex(0);
1173 else
1174 mRatioBox->setCurrentIndex(1);
1175
1176 }
1177
on_panAction_toggled(bool checked)1178 void DkCropToolBar::on_panAction_toggled(bool checked) {
1179
1180 emit panSignal(checked);
1181 }
1182
1183 // -------------------------------------------------------------------- DkToolBarManager
DkToolBarManager()1184 DkToolBarManager::DkToolBarManager() {
1185 }
1186
inst()1187 DkToolBarManager& DkToolBarManager::inst() {
1188
1189 static DkToolBarManager inst;
1190 return inst;
1191 }
1192
createDefaultToolBar()1193 void DkToolBarManager::createDefaultToolBar() {
1194
1195 if (mToolBar)
1196 return;
1197
1198 auto nomacs = dynamic_cast<QMainWindow*>(DkUtils::getMainWindow());
1199 assert(nomacs);
1200
1201 mToolBar = new DkMainToolBar(QObject::tr("Edit ToolBar"), nomacs);
1202 mToolBar->setObjectName("EditToolBar");
1203
1204 int is = DkSettingsManager::param().effectiveIconSize(nomacs);
1205 mToolBar->setIconSize(QSize(is, is));
1206
1207 // add actions
1208 DkActionManager& am = DkActionManager::instance();
1209 mToolBar->addAction(am.action(DkActionManager::menu_file_prev));
1210 mToolBar->addAction(am.action(DkActionManager::menu_file_next));
1211 mToolBar->addSeparator();
1212
1213 mToolBar->addAction(am.action(DkActionManager::menu_file_open));
1214 mToolBar->addAction(am.action(DkActionManager::menu_file_open_dir));
1215 mToolBar->addAction(am.action(DkActionManager::menu_file_save));
1216 mToolBar->addAction(am.action(DkActionManager::menu_edit_delete));
1217 mToolBar->addAction(am.action(DkActionManager::menu_tools_filter));
1218 mToolBar->addSeparator();
1219
1220 // view
1221 mToolBar->addAction(am.action(DkActionManager::menu_view_zoom_in));
1222 mToolBar->addAction(am.action(DkActionManager::menu_view_zoom_out));
1223 mToolBar->addSeparator();
1224
1225 // edit
1226 mToolBar->addAction(am.action(DkActionManager::menu_edit_copy));
1227 mToolBar->addAction(am.action(DkActionManager::menu_edit_paste));
1228 mToolBar->addSeparator();
1229 mToolBar->addAction(am.action(DkActionManager::menu_edit_rotate_ccw));
1230 mToolBar->addAction(am.action(DkActionManager::menu_edit_rotate_cw));
1231 mToolBar->addSeparator();
1232 mToolBar->addAction(am.action(DkActionManager::menu_edit_crop));
1233 mToolBar->addAction(am.action(DkActionManager::menu_edit_transform));
1234 mToolBar->addSeparator();
1235
1236 // view
1237 mToolBar->addAction(am.action(DkActionManager::menu_view_fullscreen));
1238 mToolBar->addAction(am.action(DkActionManager::menu_view_reset));
1239 mToolBar->addAction(am.action(DkActionManager::menu_view_100));
1240 mToolBar->addSeparator();
1241
1242 mToolBar->addAction(am.action(DkActionManager::menu_view_gps_map));
1243 mToolBar->allActionsAdded();
1244
1245 mMovieToolBar = nomacs->addToolBar(QObject::tr("Movie ToolBar"));
1246 mMovieToolBar->setObjectName("movieToolbar");
1247 mMovieToolBar->setIconSize(QSize(is, is));
1248 mMovieToolBar->addAction(am.action(DkActionManager::menu_view_movie_prev));
1249 mMovieToolBar->addAction(am.action(DkActionManager::menu_view_movie_pause));
1250 mMovieToolBar->addAction(am.action(DkActionManager::menu_view_movie_next));
1251
1252 nomacs->addToolBar(mToolBar);
1253 }
1254
show(bool show,bool permanent)1255 void DkToolBarManager::show(bool show, bool permanent) {
1256 showDefaultToolBar(show, permanent);
1257 showMovieToolBar(show);
1258 showToolBarsTemporarily(show);
1259 }
1260
restore()1261 void DkToolBarManager::restore() {
1262
1263 if (mToolBar)
1264 mToolBar->setVisible(DkSettingsManager::param().app().showToolBar);
1265 if (mMovieToolBar)
1266 mMovieToolBar->setVisible(DkSettingsManager::param().app().showMovieToolBar);
1267 }
1268
showToolBar(QToolBar * toolbar,bool show)1269 void DkToolBarManager::showToolBar(QToolBar* toolbar, bool show) {
1270
1271 if (!toolbar)
1272 return;
1273
1274 showToolBarsTemporarily(!show);
1275 QMainWindow* nomacs = dynamic_cast<QMainWindow*>(DkUtils::getMainWindow());
1276 assert(nomacs);
1277
1278 if (show) {
1279
1280 if (!mToolBar)
1281 createDefaultToolBar();
1282
1283 nomacs->addToolBar(nomacs->toolBarArea(mToolBar), toolbar);
1284 }
1285 else
1286 nomacs->removeToolBar(toolbar);
1287
1288 toolbar->setVisible(show);
1289 }
1290
showToolBarsTemporarily(bool show)1291 void DkToolBarManager::showToolBarsTemporarily(bool show) {
1292
1293 if (show) {
1294
1295 for (QToolBar* t : mHiddenToolBars)
1296 t->show();
1297 }
1298 else {
1299
1300 QMainWindow* nomacs = dynamic_cast<QMainWindow*>(DkUtils::getMainWindow());
1301 assert(nomacs);
1302
1303 mHiddenToolBars.clear();
1304 QList<QToolBar *> tbs = nomacs->findChildren<QToolBar *>();
1305
1306 for (QToolBar* t : tbs) {
1307
1308 if (t->isVisible()) {
1309 t->hide();
1310 mHiddenToolBars.append(t);
1311 }
1312 }
1313 }
1314 }
1315
showDefaultToolBar(bool show,bool permanent)1316 void DkToolBarManager::showDefaultToolBar(bool show, bool permanent) {
1317
1318 if (!show && !mToolBar)
1319 return;
1320
1321 if (!mToolBar)
1322 createDefaultToolBar();
1323
1324 if (mToolBar->isVisible() == show)
1325 return;
1326
1327 if (permanent)
1328 DkSettingsManager::param().app().showToolBar = show;
1329 DkActionManager::instance().action(DkActionManager::menu_panel_toolbar)->setChecked(DkSettingsManager::param().app().showToolBar);
1330
1331 mToolBar->setVisible(show);
1332 }
1333
showMovieToolBar(bool show)1334 void DkToolBarManager::showMovieToolBar(bool show) {
1335
1336 QMainWindow* nomacs = dynamic_cast<QMainWindow*>(DkUtils::getMainWindow());
1337 assert(nomacs);
1338
1339 // set movie toolbar into current toolbar
1340 if (mMovieToolbarArea == Qt::NoToolBarArea && show)
1341 mMovieToolbarArea = nomacs->toolBarArea(mToolBar);
1342
1343 if (show)
1344 nomacs->addToolBar(mMovieToolbarArea, mMovieToolBar);
1345 else {
1346 // remember if the user changed it
1347 Qt::ToolBarArea nta = nomacs->toolBarArea(mMovieToolBar);
1348
1349 if (nta != Qt::NoToolBarArea && mMovieToolBar->isVisible())
1350 mMovieToolbarArea = nomacs->toolBarArea(mMovieToolBar);
1351 nomacs->removeToolBar(mMovieToolBar);
1352 }
1353
1354 if (mToolBar && mToolBar->isVisible())
1355 mMovieToolBar->setVisible(show);
1356 }
1357
1358
createTransferToolBar()1359 void DkToolBarManager::createTransferToolBar() {
1360
1361 QMainWindow* nomacs = dynamic_cast<QMainWindow*>(DkUtils::getMainWindow());
1362 assert(nomacs);
1363
1364 mTransferToolBar = new DkTransferToolBar(nomacs);
1365
1366 // add this toolbar below all previous toolbars
1367 nomacs->addToolBarBreak();
1368 nomacs->addToolBar(mTransferToolBar);
1369 mTransferToolBar->setObjectName("TransferToolBar");
1370
1371 int is = DkSettingsManager::param().effectiveIconSize(nomacs);
1372 mTransferToolBar->setIconSize(QSize(is, is));
1373 }
1374
defaultToolBar() const1375 DkMainToolBar * DkToolBarManager::defaultToolBar() const {
1376 return mToolBar;
1377 }
1378
transferToolBar() const1379 DkTransferToolBar * DkToolBarManager::transferToolBar() const {
1380 return mTransferToolBar;
1381 }
1382
1383
1384 }
1385