1 /******************************************************************************************************* 2 DkTransferToolBar.h 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 #pragma once 29 30 #include "DkBaseWidgets.h" 31 32 #pragma warning(push, 0) // no warnings from includes - begin 33 #include <QToolBar> 34 #include <QWidget> 35 #include <QObject> 36 #include <QCompleter> 37 #pragma warning(pop) // no warnings from includes - end 38 39 #pragma warning(disable: 4251) 40 41 // Qt defines 42 class QCheckBox; 43 class QComboBox; 44 class QLineEdit; 45 class QGraphicsOpacityEffect; 46 class QDoubleSpinBox; 47 class QPushButton; 48 class QColorDialog; 49 class QStandardItemModel; 50 51 namespace nmc { 52 53 class DkTransferToolBar; 54 class DkVector; 55 class DkQuickAccess; 56 class DkQuickAccessEdit; 57 class DkRectWidget; 58 59 class DkMainToolBar : public QToolBar { 60 Q_OBJECT 61 62 public: 63 DkMainToolBar(const QString & title, QWidget * parent = 0); 64 65 void allActionsAdded(); // fast fix for now 66 void setQuickAccessModel(QStandardItemModel* model); 67 DkQuickAccessEdit* getQuickAccess() const; 68 69 public slots: 70 void closeQuickAccess(); 71 72 protected: 73 void createLayout(); 74 75 DkQuickAccessEdit* mQuickAccessEdit; 76 }; 77 78 class DkColorSlider : public DkWidget { 79 Q_OBJECT 80 81 public: 82 //DkColorSlider(QWidget *parent); 83 DkColorSlider(QWidget *parent, QColor color); 84 DkColorSlider(QWidget *parent, qreal normedPos, QColor color, int sliderWidth); 85 ~DkColorSlider(); 86 QColor getColor(); 87 qreal getNormedPos(); 88 void setNormedPos(qreal pos); 89 void setActive(bool isActive); 90 void updatePos(int parentWidth); 91 92 //void paintSlider(QPainter *painter); 93 94 signals: 95 void sliderMoved(DkColorSlider *sender, int dragDistX, int yPos) const; 96 void sliderActivated(DkColorSlider *sender) const; 97 void colorChanged(DkColorSlider *slider) const; 98 99 public slots: 100 virtual void paintEvent(QPaintEvent* event) override; 101 102 protected: 103 virtual void mousePressEvent(QMouseEvent *event) override; 104 virtual void mouseMoveEvent(QMouseEvent *event) override; 105 virtual void mouseDoubleClickEvent(QMouseEvent *event) override; 106 107 private: 108 int mSliderWidth = 0, mSliderHeight = 0, mSliderHalfWidth = 0; 109 bool mIsActive = false; 110 int mDragStartX = 0; 111 QColor mColor; 112 qreal mNormedPos; 113 }; 114 115 class DkGradient : public DkWidget { 116 Q_OBJECT 117 118 public: 119 DkGradient(QWidget *parent); 120 ~DkGradient(); 121 QGradientStops getGradientStops(); 122 void insertSlider(qreal pos, QColor col = QColor()); 123 void reset(); 124 QLinearGradient getGradient(); 125 void setGradient(const QLinearGradient& gradient); 126 127 signals: 128 void gradientChanged() const; 129 130 public slots: 131 void moveSlider(DkColorSlider* sender, int dragDistX, int yPos); 132 void changeColor(DkColorSlider *slider); 133 void activateSlider(DkColorSlider *sender); 134 135 protected: 136 virtual void paintEvent(QPaintEvent* event) override; 137 virtual void mousePressEvent(QMouseEvent *event) override; 138 virtual void mouseReleaseEvent(QMouseEvent *event) override; 139 virtual void resizeEvent(QResizeEvent * event) override; 140 141 private: 142 void init(); 143 void addSlider(qreal pos, QColor color); 144 void clearAllSliders(); 145 void updateGradient(); 146 qreal getNormedPos(int pos); 147 int getAbsolutePos(qreal pos); 148 149 int mClickAreaHeight; 150 int mDeleteSliderDist; 151 QVector<DkColorSlider*> mSliders; 152 bool mIsSliderDragged = false; 153 QLinearGradient mGradient; 154 int mSliderWidth = 0, mHalfSliderWidth = 0; 155 156 DkColorSlider *mActiveSlider = 0; 157 bool mIsActiveSliderExisting = false; 158 }; 159 160 enum toolBarIcons { 161 icon_toolbar_reset, 162 icon_toolbar_pipette, 163 icon_toolbar_save, 164 icon_toolbar_end, // nothing beyond this point 165 }; 166 167 enum toolBarActions { 168 toolbar_save, 169 toolbar_reset, 170 toolbar_pipette, 171 toolbar_end, // nothing beyond this point 172 }; 173 174 enum imageModes { 175 mode_uninitialized, 176 mode_invalid_format, 177 mode_gray, 178 mode_rgb, 179 }; 180 181 class DkTransferToolBar : public QToolBar { 182 Q_OBJECT 183 184 public: 185 DkTransferToolBar(QWidget *parent); 186 ~DkTransferToolBar(); 187 188 189 signals: 190 void pickColorRequest(bool enabled) const; 191 void colorTableChanged(QGradientStops stops) const; 192 void channelChanged(int channel) const; 193 void transferFunctionChanged(int channel, QGradientStops stops) const; 194 void tFEnabled(bool) const; 195 void gradientChanged() const; 196 197 public slots: 198 virtual void paintEvent(QPaintEvent* event) override; 199 void insertSlider(qreal pos); 200 void setImageMode(int mode); 201 void saveGradient(); 202 void deleteGradientMenu(QPoint pos); 203 void deleteGradient(); 204 void resetGradient(); 205 206 protected slots: 207 void applyTF(); 208 void pickColor(bool enabled); 209 void changeChannel(int index); 210 void enableTFCheckBoxClicked(int state); 211 void switchGradient(int idx); 212 213 protected: 214 virtual void resizeEvent(QResizeEvent * event) override; 215 void loadSettings(); 216 void saveSettings(); 217 void updateGradientHistory(); 218 219 private: 220 void createIcons(); 221 void applyImageMode(int mode); 222 void enableToolBar(bool enable); 223 224 QCheckBox *mEnableTFCheckBox = 0; 225 226 QImage mShade; 227 QImage mSliderImg, mActiveSliderImg; 228 229 QVector<QAction *> mToolBarActions; 230 QVector<QIcon> mToolBarIcons; 231 232 DkGradient *mGradient = 0; 233 QComboBox *mChannelComboBox = 0; 234 235 QComboBox* mHistoryCombo = 0; 236 QVector<QLinearGradient> mOldGradients; 237 238 QGraphicsOpacityEffect *mEffect = 0; 239 int mImageMode = mode_uninitialized; 240 241 }; 242 243 class DkCropToolBar : public QToolBar { 244 Q_OBJECT 245 246 public: 247 248 enum { 249 crop_icon = 0, 250 pan_icon, 251 cancel_icon, 252 invert_icon, 253 info_icon, 254 255 icons_end, 256 257 }; 258 259 DkCropToolBar(const QString & title, QWidget * parent = 0); 260 virtual ~DkCropToolBar(); 261 getColor()262 QColor getColor() { 263 return mBgCol; 264 }; 265 266 void loadSettings(); 267 268 public slots: 269 void setAspectRatio(const QPointF& aRatio); 270 void setRect(const QRect& r); 271 void on_cropAction_triggered(); 272 void on_cancelAction_triggered(); 273 void on_swapAction_triggered(); 274 void on_ratioBox_currentIndexChanged(const QString& text); 275 void on_guideBox_currentIndexChanged(int idx); 276 void on_horValBox_valueChanged(double val); 277 void on_verValBox_valueChanged(double val); 278 void on_angleBox_valueChanged(double val); 279 void on_bgColButton_clicked(); 280 void on_panAction_toggled(bool checked); 281 void on_invertAction_toggled(bool checked); 282 void on_infoAction_toggled(bool checked); 283 void angleChanged(double val); 284 virtual void setVisible(bool visible) override; 285 286 signals: 287 void panSignal(bool checked); 288 void cropSignal(bool cropToMetadata = false); // vs. crop 289 void cancelSignal(); 290 void aspectRatio(const DkVector& diag); 291 void angleSignal(double angle); 292 void colorSignal(const QBrush& brush); 293 void paintHint(int paintMode); 294 void shadingHint(bool invert); 295 void showInfo(bool show); 296 void updateRectSignal(const QRect& r); 297 298 protected: 299 void createLayout(); 300 void createIcons(); 301 void saveSettings(); 302 303 QComboBox* mRatioBox = 0; 304 QComboBox* mGuideBox = 0; 305 QAction* mInvertAction = 0; 306 QDoubleSpinBox* mHorValBox = 0; 307 QDoubleSpinBox* mVerValBox = 0; 308 QDoubleSpinBox* mAngleBox = 0; 309 QPushButton* mBgColButton = 0; 310 QColorDialog* mColorDialog = 0; 311 QColor mBgCol; 312 QAction* mPanAction = 0; 313 QAction* mInfoAction = 0; 314 QCheckBox* mCbMeta = 0; 315 DkRectWidget* mCropRect = 0; 316 317 QVector<QIcon> mIcons; // needed for colorizing 318 }; 319 320 class DllCoreExport DkToolBarManager { 321 322 public: 323 static DkToolBarManager& inst(); 324 325 // singleton 326 DkToolBarManager(DkToolBarManager const&) = delete; 327 void operator=(DkToolBarManager const&) = delete; 328 329 void showDefaultToolBar(bool show, bool permanent = true); 330 void showMovieToolBar(bool show); 331 void show(bool show, bool permanent = false); 332 void restore(); 333 void showToolBar(QToolBar* toolbar, bool show); 334 void showToolBarsTemporarily(bool show); 335 336 void createTransferToolBar(); 337 338 DkMainToolBar* defaultToolBar() const; 339 DkTransferToolBar* transferToolBar() const; 340 341 private: 342 DkToolBarManager(); 343 void createDefaultToolBar(); 344 345 DkMainToolBar* mToolBar = 0; 346 QToolBar* mMovieToolBar = 0; 347 QVector<QToolBar*> mHiddenToolBars; 348 Qt::ToolBarArea mMovieToolbarArea = Qt::NoToolBarArea; 349 350 DkTransferToolBar* mTransferToolBar = 0; 351 352 }; 353 354 355 } 356