Changeset View
Changeset View
Standalone View
Standalone View
lib/zoomwidget.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | struct ZoomWidgetPrivate | 57 | struct ZoomWidgetPrivate | ||
58 | { | 58 | { | ||
59 | ZoomWidget* q; | 59 | ZoomWidget* q; | ||
60 | 60 | | |||
61 | StatusBarToolButton* mZoomToFitButton; | 61 | StatusBarToolButton* mZoomToFitButton; | ||
62 | StatusBarToolButton* mActualSizeButton; | 62 | StatusBarToolButton* mActualSizeButton; | ||
63 | StatusBarToolButton* mZoomToFitWidthButton; | 63 | StatusBarToolButton* mZoomToFillButton; | ||
64 | QLabel* mZoomLabel; | 64 | QLabel* mZoomLabel; | ||
65 | ZoomSlider* mZoomSlider; | 65 | ZoomSlider* mZoomSlider; | ||
66 | QAction* mZoomToFitAction; | 66 | QAction* mZoomToFitAction; | ||
67 | QAction* mActualSizeAction; | 67 | QAction* mActualSizeAction; | ||
68 | QAction* mZoomToFitWidthAction; | 68 | QAction* mZoomToFillAction; | ||
69 | 69 | | |||
70 | bool mZoomUpdatedBySlider; | 70 | bool mZoomUpdatedBySlider; | ||
71 | 71 | | |||
72 | void emitZoomChanged() | 72 | void emitZoomChanged() | ||
73 | { | 73 | { | ||
74 | // Use QSlider::sliderPosition(), not QSlider::value() because when we are | 74 | // Use QSlider::sliderPosition(), not QSlider::value() because when we are | ||
75 | // called from slotZoomSliderActionTriggered(), QSlider::value() has not | 75 | // called from slotZoomSliderActionTriggered(), QSlider::value() has not | ||
76 | // been updated yet. | 76 | // been updated yet. | ||
Show All 10 Lines | |||||
87 | { | 87 | { | ||
88 | d->q = this; | 88 | d->q = this; | ||
89 | d->mZoomUpdatedBySlider = false; | 89 | d->mZoomUpdatedBySlider = false; | ||
90 | 90 | | |||
91 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | 91 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | ||
92 | 92 | | |||
93 | d->mZoomToFitButton = new StatusBarToolButton; | 93 | d->mZoomToFitButton = new StatusBarToolButton; | ||
94 | d->mActualSizeButton = new StatusBarToolButton; | 94 | d->mActualSizeButton = new StatusBarToolButton; | ||
95 | d->mZoomToFitWidthButton = new StatusBarToolButton; | 95 | d->mZoomToFillButton = new StatusBarToolButton; | ||
96 | d->mZoomToFitButton->setCheckable(true); | 96 | d->mZoomToFitButton->setCheckable(true); | ||
97 | d->mActualSizeButton->setCheckable(true); | 97 | d->mActualSizeButton->setCheckable(true); | ||
98 | d->mZoomToFitWidthButton->setCheckable(true); | 98 | d->mZoomToFillButton->setCheckable(true); | ||
99 | d->mZoomToFitButton->setChecked(true); | 99 | d->mZoomToFitButton->setChecked(true); | ||
100 | 100 | | |||
101 | if (QApplication::isLeftToRight()) { | 101 | if (QApplication::isLeftToRight()) { | ||
102 | d->mZoomToFitButton->setGroupPosition(StatusBarToolButton::GroupLeft); | 102 | d->mZoomToFitButton->setGroupPosition(StatusBarToolButton::GroupLeft); | ||
103 | d->mZoomToFitWidthButton->setGroupPosition(StatusBarToolButton::GroupCenter); | 103 | d->mZoomToFillButton->setGroupPosition(StatusBarToolButton::GroupCenter); | ||
104 | d->mActualSizeButton->setGroupPosition(StatusBarToolButton::GroupRight); | 104 | d->mActualSizeButton->setGroupPosition(StatusBarToolButton::GroupRight); | ||
105 | } else { | 105 | } else { | ||
106 | d->mActualSizeButton->setGroupPosition(StatusBarToolButton::GroupLeft); | 106 | d->mActualSizeButton->setGroupPosition(StatusBarToolButton::GroupLeft); | ||
107 | d->mZoomToFitWidthButton->setGroupPosition(StatusBarToolButton::GroupCenter); | 107 | d->mZoomToFillButton->setGroupPosition(StatusBarToolButton::GroupCenter); | ||
108 | d->mZoomToFitButton->setGroupPosition(StatusBarToolButton::GroupRight); | 108 | d->mZoomToFitButton->setGroupPosition(StatusBarToolButton::GroupRight); | ||
109 | } | 109 | } | ||
110 | 110 | | |||
111 | d->mZoomLabel = new QLabel; | 111 | d->mZoomLabel = new QLabel; | ||
112 | d->mZoomLabel->setFixedWidth(d->mZoomLabel->fontMetrics().width(" 1000% ")); | 112 | d->mZoomLabel->setFixedWidth(d->mZoomLabel->fontMetrics().width(" 1000% ")); | ||
113 | d->mZoomLabel->setAlignment(Qt::AlignCenter); | 113 | d->mZoomLabel->setAlignment(Qt::AlignCenter); | ||
114 | 114 | | |||
115 | d->mZoomSlider = new ZoomSlider; | 115 | d->mZoomSlider = new ZoomSlider; | ||
116 | d->mZoomSlider->setMinimumWidth(150); | 116 | d->mZoomSlider->setMinimumWidth(150); | ||
117 | d->mZoomSlider->slider()->setSingleStep(int(PRECISION)); | 117 | d->mZoomSlider->slider()->setSingleStep(int(PRECISION)); | ||
118 | d->mZoomSlider->slider()->setPageStep(3 * int(PRECISION)); | 118 | d->mZoomSlider->slider()->setPageStep(3 * int(PRECISION)); | ||
119 | connect(d->mZoomSlider->slider(), SIGNAL(actionTriggered(int)), SLOT(slotZoomSliderActionTriggered())); | 119 | connect(d->mZoomSlider->slider(), SIGNAL(actionTriggered(int)), SLOT(slotZoomSliderActionTriggered())); | ||
120 | 120 | | |||
121 | // Layout | 121 | // Layout | ||
122 | QHBoxLayout* layout = new QHBoxLayout(this); | 122 | QHBoxLayout* layout = new QHBoxLayout(this); | ||
123 | layout->setMargin(0); | 123 | layout->setMargin(0); | ||
124 | layout->setSpacing(0); | 124 | layout->setSpacing(0); | ||
125 | layout->addWidget(d->mZoomToFitButton); | 125 | layout->addWidget(d->mZoomToFitButton); | ||
126 | layout->addWidget(d->mZoomToFitWidthButton); | 126 | layout->addWidget(d->mZoomToFillButton); | ||
127 | layout->addWidget(d->mActualSizeButton); | 127 | layout->addWidget(d->mActualSizeButton); | ||
128 | layout->addWidget(d->mZoomSlider); | 128 | layout->addWidget(d->mZoomSlider); | ||
129 | layout->addWidget(d->mZoomLabel); | 129 | layout->addWidget(d->mZoomLabel); | ||
130 | } | 130 | } | ||
131 | 131 | | |||
132 | ZoomWidget::~ZoomWidget() | 132 | ZoomWidget::~ZoomWidget() | ||
133 | { | 133 | { | ||
134 | delete d; | 134 | delete d; | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | void ZoomWidget::setActions(QAction* zoomToFitAction, QAction* actualSizeAction, QAction* zoomInAction, QAction* zoomOutAction, QAction* zoomToFitWidthAction) | 137 | void ZoomWidget::setActions(QAction* zoomToFitAction, QAction* actualSizeAction, QAction* zoomInAction, QAction* zoomOutAction, QAction* zoomToFillAction) | ||
138 | { | 138 | { | ||
139 | d->mZoomToFitAction = zoomToFitAction; | 139 | d->mZoomToFitAction = zoomToFitAction; | ||
140 | d->mActualSizeAction = actualSizeAction; | 140 | d->mActualSizeAction = actualSizeAction; | ||
141 | d->mZoomToFitWidthAction = zoomToFitWidthAction; | 141 | d->mZoomToFillAction = zoomToFillAction; | ||
142 | 142 | | |||
143 | d->mZoomToFitButton->setDefaultAction(zoomToFitAction); | 143 | d->mZoomToFitButton->setDefaultAction(zoomToFitAction); | ||
144 | d->mActualSizeButton->setDefaultAction(actualSizeAction); | 144 | d->mActualSizeButton->setDefaultAction(actualSizeAction); | ||
145 | d->mZoomToFitWidthButton->setDefaultAction(zoomToFitWidthAction); | 145 | d->mZoomToFillButton->setDefaultAction(zoomToFillAction); | ||
146 | 146 | | |||
147 | d->mZoomSlider->setZoomInAction(zoomInAction); | 147 | d->mZoomSlider->setZoomInAction(zoomInAction); | ||
148 | d->mZoomSlider->setZoomOutAction(zoomOutAction); | 148 | d->mZoomSlider->setZoomOutAction(zoomOutAction); | ||
149 | 149 | | |||
150 | QActionGroup *actionGroup = new QActionGroup(d->q); | 150 | QActionGroup *actionGroup = new QActionGroup(d->q); | ||
151 | actionGroup->addAction(d->mZoomToFitAction); | 151 | actionGroup->addAction(d->mZoomToFitAction); | ||
152 | actionGroup->addAction(d->mZoomToFitWidthAction); | 152 | actionGroup->addAction(d->mZoomToFillAction); | ||
153 | actionGroup->addAction(d->mActualSizeAction); | 153 | actionGroup->addAction(d->mActualSizeAction); | ||
154 | actionGroup->setExclusive(true); | 154 | actionGroup->setExclusive(true); | ||
155 | 155 | | |||
156 | // Adjust sizes | 156 | // Adjust sizes | ||
157 | int width = qMax(d->mZoomToFitButton->sizeHint().width(), d->mActualSizeButton->sizeHint().width()); | 157 | int width = std::max({d->mZoomToFitButton->sizeHint().width(), d->mActualSizeButton->sizeHint().width(), d->mZoomToFillButton->sizeHint().width()}); | ||
slenz: This switches D8306 to the "equal width" option, as Fill should be about as short as Fit… | |||||
Is there a more legible way for this? Sorry, don't have a concrete proposal just wondering. ;) muhlenpfordt: Is there a more legible way for this? Sorry, don't have a concrete proposal just wondering. ;) | |||||
We could use c++11 features and do std::max({x,y,z}). But as far as i can tell we still support Qt 5.6, which doesn't require a C++11 compiler so this is probably the best way... slenz: We could use c++11 features and do `std::max({x,y,z})`. But as far as i can tell we still… | |||||
Haha, that's exactly how I implemented it for my screenshot back in October. I tried it with GCC 4.8 + Qt 5.6 and found that CMake turns on C++11 mode for us anyway. AFAIK Qt is much more conservative than we are. Let's try the initializer list approach for now. rkflx: Haha, that's exactly how I implemented it for my screenshot back in October. I tried it with… | |||||
158 | d->mZoomToFitButton->setFixedWidth(width); | 158 | d->mZoomToFitButton->setFixedWidth(width); | ||
159 | d->mActualSizeButton->setFixedWidth(width); | 159 | d->mActualSizeButton->setFixedWidth(width); | ||
160 | d->mZoomToFillButton->setFixedWidth(width); | ||||
160 | } | 161 | } | ||
161 | 162 | | |||
162 | void ZoomWidget::slotZoomSliderActionTriggered() | 163 | void ZoomWidget::slotZoomSliderActionTriggered() | ||
163 | { | 164 | { | ||
164 | // The slider value changed because of the user (not because of range | 165 | // The slider value changed because of the user (not because of range | ||
165 | // changes). In this case disable zoom and apply slider value. | 166 | // changes). In this case disable zoom and apply slider value. | ||
166 | d->emitZoomChanged(); | 167 | d->emitZoomChanged(); | ||
167 | } | 168 | } | ||
Show All 33 Lines |
This switches D8306 to the "equal width" option, as Fill should be about as short as Fit, weighing the the space vs symmetry decision towards symmetry (unless some language is an exception, in which case we have to switch back...).