Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsGuideline.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "ButtonWhatsThis.h"
14#include "EngaugeAssert.h"
15#include "EnumsToQt.h"
16#include "GraphicsArcItem.h"
17#include "GraphicsScene.h"
20#include "ImportCropping.h"
22#include "Logger.h"
23#include "MainWindow.h"
24#include "mmsubs.h"
25#include <QApplication>
26#include <QCheckBox>
27#include <QComboBox>
28#include <qdebug.h>
29#include <QDir>
30#include <QDoubleSpinBox>
31#include <QGraphicsLineItem>
32#include <QGraphicsScene>
33#include <QGridLayout>
34#include <QGroupBox>
35#include <QLabel>
36#include <qmath.h>
37#include <QPen>
38#include <QPushButton>
39#include <QSpinBox>
40#include <QtGui>
41#include "QtToString.h"
42#include <QWhatsThis>
43#include "TranslatorContainer.h"
44#include "ViewPreview.h"
45
46const int MINIMUM_HEIGHT = 300;
48const int MINIMUM_PREVIEW_WIDTH = 200;
49const double T_REFERENCE = 0;
50const double RADIANS_TO_TICS = (180 * 16) / M_PI;
51
53 DlgSettingsAbstractBase (tr ("Guidelines"),
54 "DlgSettingsGuideline",
56 m_scenePreviewActive (nullptr),
57 m_viewPreviewActive (nullptr),
58 m_scenePreviewInactive (nullptr),
59 m_viewPreviewInactive (nullptr),
60 m_itemGuidelineXTActive (nullptr),
61 m_itemGuidelineYActive (nullptr),
62 m_itemGuidelineRActive (nullptr),
63 m_itemCentipedeXTActive (nullptr),
64 m_itemCentipedeYActive (nullptr),
65 m_itemCentipedeRActive (nullptr),
66 m_itemCentipedeCircleActive (nullptr),
67 m_itemGuidelineXTInactive (nullptr),
68 m_itemGuidelineYInactive (nullptr),
69 m_itemGuidelineRInactive (nullptr),
70 m_modelGuidelineBefore (nullptr),
71 m_modelGuidelineAfter (nullptr)
72{
73 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::DlgSettingsGuideline";
74
75 QWidget *subPanel = createSubPanel ();
76 finishPanel (subPanel,
78}
79
81{
82 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::~DlgSettingsGuideline";
83}
84
85void DlgSettingsGuideline::createCircle ()
86{
87 m_itemCentipedeCircleActive = new QGraphicsEllipseItem ();
88
89 m_itemCentipedeCircleActive->setPen (QPen (Qt::black, 1, Qt::DotLine));
90
91 m_scenePreviewActive->addItem (m_itemCentipedeCircleActive);
92
93}
94void DlgSettingsGuideline::createControls (QGridLayout *layout,
95 int &row)
96{
97 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::createControls";
98
99 createWhatsThis (layout,
100 m_btnWhatsThis,
101 row++,
102 3);
103
104 QLabel *labelPointRadius = new QLabel (QString ("%1:").arg (tr ("Creation circle radius")));
105 layout->addWidget (labelPointRadius, row, 1);
106
107 m_spinCreationCircleRadius = new QSpinBox;
108 m_spinCreationCircleRadius->setWhatsThis (tr ("Select a radius, in pixels, for the points"));
109 m_spinCreationCircleRadius->setMinimum (1);
110 connect (m_spinCreationCircleRadius, SIGNAL (valueChanged (int)), this, SLOT (slotCreationCircleRadius (int)));
111 layout->addWidget (m_spinCreationCircleRadius, row++, 2);
112
113 QLabel *labelGuidelineColor = new QLabel (QString ("%1:").arg (tr ("Guideline color")));
114 layout->addWidget (labelGuidelineColor, row, 1);
115
116 m_lineColor = new QComboBox;
117 m_lineColor->setWhatsThis (tr ("Guidelines Color\n\n"
118 "Set the color of the guidelines that can be dragged from the edges of the scene, and used "
119 "to align points"));
121 connect (m_lineColor, SIGNAL (activated (const QString &)), this, SLOT (slotLineColor (const QString &))); // activated() ignores code changes
122 layout->addWidget (m_lineColor, row++, 2);
123
124 QLabel *labelLineWidthActive = new QLabel(QString ("%1:").arg (tr ("Active Line width")));
125 layout->addWidget (labelLineWidthActive, row, 1);
126
127 m_spinLineWidthActive = new QSpinBox;
128 m_spinLineWidthActive->setWhatsThis (tr ("Select a size for the guidelines when active"));
129 m_spinLineWidthActive->setMinimum(1);
130 connect (m_spinLineWidthActive, SIGNAL (valueChanged (int)), this, SLOT (slotLineWidthActive (int)));
131 layout->addWidget (m_spinLineWidthActive, row++, 2);
132
133 QLabel *labelLineWidthInactive = new QLabel(QString ("%1:").arg (tr ("Inactive Line width")));
134 layout->addWidget (labelLineWidthInactive, row, 1);
135
136 m_spinLineWidthInactive = new QSpinBox;
137 m_spinLineWidthInactive->setWhatsThis (tr ("Select a size for the guidelines when inactive"));
138 m_spinLineWidthInactive->setMinimum(1);
139 connect (m_spinLineWidthInactive, SIGNAL (valueChanged (int)), this, SLOT (slotLineWidthInactive (int)));
140 layout->addWidget (m_spinLineWidthInactive, row++, 2);
141}
142
143void DlgSettingsGuideline::createLines ()
144{
145 // Centipedes circle (for active only) which is the same for both cartesian and polar coordinates.
146 // This is created first so it is underneath the other items
147 createCircle ();
148
149 if (cmdMediator().document().modelCoords().coordsType() == COORDS_TYPE_CARTESIAN) {
150 createLinesCartesian();
151 } else {
152 createLinesPolar();
153 }
154}
155
156void DlgSettingsGuideline::createLinesCartesian ()
157{
158 m_itemGuidelineXTActive = new QGraphicsLineItem ();
159 m_itemGuidelineYActive = new QGraphicsLineItem ();
160 m_itemGuidelineXTInactive = new QGraphicsLineItem ();
161 m_itemGuidelineYInactive = new QGraphicsLineItem ();
162
163 m_scenePreviewActive->addItem (m_itemGuidelineXTActive);
164 m_scenePreviewActive->addItem (m_itemGuidelineYActive);
165 m_scenePreviewInactive->addItem (m_itemGuidelineXTInactive);
166 m_scenePreviewInactive->addItem (m_itemGuidelineYInactive);
167
168 m_itemCentipedeXTActive = new QGraphicsLineItem ();
169 m_itemCentipedeYActive = new QGraphicsLineItem ();
170
171 m_scenePreviewActive->addItem (m_itemCentipedeXTActive);
172 m_scenePreviewActive->addItem (m_itemCentipedeYActive);
173}
174
175void DlgSettingsGuideline::createLinesPolar ()
176{
177 m_itemGuidelineXTActive = new QGraphicsLineItem ();
178 m_itemGuidelineRActive = new QGraphicsEllipseItem ();
179 m_itemGuidelineXTInactive = new QGraphicsLineItem ();
180 m_itemGuidelineRInactive = new QGraphicsEllipseItem ();
181
182 m_scenePreviewActive->addItem (m_itemGuidelineXTActive);
183 m_scenePreviewActive->addItem (m_itemGuidelineRActive);
184 m_scenePreviewInactive->addItem (m_itemGuidelineXTInactive);
185 m_scenePreviewInactive->addItem (m_itemGuidelineRInactive);
186
187 m_itemCentipedeXTActive = new QGraphicsLineItem();
188 m_itemCentipedeRActive = new GraphicsArcItem ();
189
190 m_scenePreviewActive->addItem (m_itemCentipedeXTActive);
191 m_scenePreviewActive->addItem (m_itemCentipedeRActive);
192}
193
194void DlgSettingsGuideline::createOptionalSaveDefault (QHBoxLayout * /* layout */)
195{
196 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::createOptionalSaveDefault";
197}
198
199void DlgSettingsGuideline::createPreview (QGridLayout *layout, int &row)
200{
201 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::createPreview";
202
203 // Need local gridlayout to get nicely even 50/50 split
204 int row5050 = 0;
205 QGridLayout *layout5050 = new QGridLayout();
206 QWidget *widget = new QWidget();
207 widget->setLayout (layout5050);
208
209 // Preview panels
210
211 QLabel *labelPreviewActive = new QLabel (tr ("Active Preview"));
212 layout5050->addWidget (labelPreviewActive, row5050, 0, 1, 2);
213
214 QLabel *labelPreviewInactive = new QLabel (tr ("Inactive Preview"));
215 layout5050->addWidget (labelPreviewInactive, row5050++, 2, 1, 2);
216
217 m_scenePreviewActive = new QGraphicsScene (this);
218 m_viewPreviewActive = new ViewPreview (m_scenePreviewActive,
220 this);
221 m_viewPreviewActive->setWhatsThis (tr ("Preview window that shows how current settings affect the active guidelines."));
222 m_viewPreviewActive->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
223 m_viewPreviewActive->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
224 m_viewPreviewActive->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
225 m_viewPreviewActive->setMinimumWidth(MINIMUM_PREVIEW_WIDTH);
226 m_viewPreviewActive->setRenderHint(QPainter::Antialiasing);
227
228 layout5050->addWidget (m_viewPreviewActive, row5050, 0, 1, 2);
229
230 m_scenePreviewInactive = new QGraphicsScene (this);
231 m_viewPreviewInactive = new ViewPreview (m_scenePreviewInactive,
233 this);
234 m_viewPreviewInactive->setWhatsThis (tr ("Preview window that shows how current settings affect the inactive guidelines."));
235 m_viewPreviewInactive->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
236 m_viewPreviewInactive->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
237 m_viewPreviewInactive->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
238 m_viewPreviewInactive->setMinimumWidth(MINIMUM_PREVIEW_WIDTH);
239 m_viewPreviewInactive->setRenderHint(QPainter::Antialiasing);
240
241 layout5050->addWidget (m_viewPreviewInactive, row5050++, 2, 1, 2);
242
243 layout->addWidget (widget, row++, 0, 1, 4);
244}
245
247{
248 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::createSubPanel";
249
250 QWidget *subPanel = new QWidget ();
251 QGridLayout *layout = new QGridLayout (subPanel);
252 subPanel->setLayout (layout);
253
254 layout->setColumnStretch(0, 1); // Empty first column
255 layout->setColumnStretch(1, 0); // Labels
256 layout->setColumnStretch(2, 0); // Values
257 layout->setColumnStretch(3, 1); // Empty first column
258
259 int row = 0;
260 createControls (layout, row);
261 createPreview (layout, row);
262
263 return subPanel;
264}
265
267{
268 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::handleOk";
269
271 cmdMediator().document(),
272 *m_modelGuidelineBefore,
273 *m_modelGuidelineAfter);
274 cmdMediator ().push (cmd);
275
276 hide ();
277}
278
280{
281 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::load";
282
284
285 // Flush old data
286 delete m_modelGuidelineBefore;
287 delete m_modelGuidelineAfter;
288
289 // Save new data
290 m_modelGuidelineBefore = new DocumentModelGuideline (cmdMediator.document());
291 m_modelGuidelineAfter = new DocumentModelGuideline (cmdMediator.document());
292
293 // Populate controls
294 m_spinCreationCircleRadius->setValue (qFloor (m_modelGuidelineAfter->creationCircleRadius ()));
295 int indexColor = m_lineColor->findData(QVariant(m_modelGuidelineAfter->lineColor()));
296 ENGAUGE_ASSERT (indexColor >= 0);
297 m_lineColor->setCurrentIndex(indexColor);
298 m_spinLineWidthActive->setValue (qFloor (m_modelGuidelineAfter->lineWidthActive ()));
299 m_spinLineWidthInactive->setValue (qFloor (m_modelGuidelineAfter->lineWidthInactive ()));
300
301 removeOldWidgetsActive();
302 removeOldWidgetsInactive();
303 loadImages (cmdMediator);
304 createLines();
305 updatePreview();
306 updateControls ();
307 enableOk (false); // Disable Ok button since there not yet any changes
308}
309
310void DlgSettingsGuideline::loadImages (CmdMediator &cmdMediator)
311{
312
313 // At this point, but not earlier, it is safe to clear the scene to remove the old images if there
314 // are any. Those images could reappear if the new image is smaller than the old one
315 m_scenePreviewActive->clear();
316 m_scenePreviewInactive->clear();
317
318 QImage imagePreviewActive = cmdMediator.document().pixmap().toImage();
319 addPixmap (*m_scenePreviewActive,
320 QPixmap::fromImage (imagePreviewActive));
321
322 QImage imagePreviewInactive = cmdMediator.document().pixmap().toImage();
323 addPixmap (*m_scenePreviewInactive,
324 QPixmap::fromImage (imagePreviewInactive));
325}
326
327double DlgSettingsGuideline::radiusOfClosestSide (const QPointF &posLeft,
328 const QPointF &posRight,
329 const QPointF &posTop,
330 const QPointF &posBottom) const
331{
332 // Convert incoming screen coordinates to graph coordinates
333 QPointF posLeftGraph, posRightGraph, posTopGraph, posBottomGraph;
335 posLeftGraph);
337 posRightGraph);
339 posTopGraph);
341 posBottomGraph);
342
343 return qMin (qMin (qMin (posLeftGraph.y(), posRightGraph.y()), posTopGraph.y()), posBottomGraph.y());
344}
345
346void DlgSettingsGuideline::removeOldWidgetsActive ()
347{
348 delete m_itemGuidelineXTActive;
349 delete m_itemGuidelineYActive;
350 delete m_itemGuidelineRActive;
351 delete m_itemCentipedeXTActive;
352 delete m_itemCentipedeYActive;
353 delete m_itemCentipedeRActive;
354 delete m_itemCentipedeCircleActive;
355
356 m_itemGuidelineXTActive = nullptr;
357 m_itemGuidelineYActive = nullptr;
358 m_itemGuidelineRActive = nullptr;
359 m_itemCentipedeXTActive = nullptr;
360 m_itemCentipedeYActive = nullptr;
361 m_itemCentipedeRActive = nullptr;
362 m_itemCentipedeCircleActive = nullptr;
363}
364
365void DlgSettingsGuideline::removeOldWidgetsInactive ()
366{
367 delete m_itemGuidelineXTInactive;
368 delete m_itemGuidelineYInactive;
369 delete m_itemGuidelineRInactive;
370
371 m_itemGuidelineXTInactive = nullptr;
372 m_itemGuidelineYInactive = nullptr;
373 m_itemGuidelineRInactive = nullptr;
374}
375
377{
378 if (!smallDialogs) {
379 setMinimumHeight (MINIMUM_HEIGHT);
380 }
381}
382
383void DlgSettingsGuideline::safeSetEllipseGeometry (QGraphicsEllipseItem *ellipse,
384 const QRectF &rectBounding,
385 double angleRotation,
386 double angleLow,
387 double angleHigh)
388{
389 if (ellipse) {
390 ellipse->setRect (rectBounding);
391 ellipse->setStartAngle (angleLow * RADIANS_TO_TICS);
392 ellipse->setSpanAngle ((angleHigh - angleLow) * RADIANS_TO_TICS);
393 ellipse->setRotation (-1.0 * qRadiansToDegrees (angleRotation));
394 ellipse->setTransformOriginPoint (rectBounding.x() + rectBounding.width() / 2.0,
395 rectBounding.y() + rectBounding.height() / 2.0);
396 }
397}
398
399void DlgSettingsGuideline::safeSetEllipseStyle (QGraphicsEllipseItem *ellipse,
400 double width)
401{
402 if (ellipse) {
403 ellipse->setPen (QPen (QBrush (ColorPaletteToQColor (m_modelGuidelineAfter->lineColor())),
404 width));
405 }
406}
407
408void DlgSettingsGuideline::safeSetLine (QGraphicsLineItem *item,
409 const QPointF &posStart,
410 const QPointF &posStop) const
411{
412 if (item) {
413 item->setLine (QLineF (posStart,
414 posStop));
415 }
416}
417
418void DlgSettingsGuideline::safeSetLineStyle (QGraphicsLineItem *line,
419 double width)
420{
421 if (line) {
422 line->setPen (QPen (QBrush (ColorPaletteToQColor (m_modelGuidelineAfter->lineColor())),
423 width));
424 }
425}
426
427void DlgSettingsGuideline::safeSetPos (QGraphicsEllipseItem *ellipse,
428 const QPointF &pos)
429{
430 if (ellipse) {
431 ellipse->setPos (pos);
432 }
433}
434
435void DlgSettingsGuideline::safeSetRect (QGraphicsEllipseItem *ellipse,
436 const QRectF &rect)
437{
438 if (ellipse) {
439 ellipse->setRect (rect);
440 }
441}
442
443void DlgSettingsGuideline::safeSetRotation (QGraphicsEllipseItem *ellipse,
444 double angle)
445{
446 if (ellipse) {
447 ellipse->setRotation (angle);
448 }
449}
450
451void DlgSettingsGuideline::slotCreationCircleRadius (int radius)
452{
453 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::slotCreationCircleRadius";
454
455 m_modelGuidelineAfter->setCreationCircleRadius (radius);
456 updateControls();
457 updatePreview();
458}
459
460void DlgSettingsGuideline::slotLineColor (QString const &)
461{
462 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::slotLineColor";
463
464 m_modelGuidelineAfter->setLineColor(static_cast<ColorPalette> (m_lineColor->currentData().toInt()));
465 updateControls();
466 updatePreview();
467}
468
469void DlgSettingsGuideline::slotLineWidthActive (int lineWidth)
470{
471 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::slotLineWidthActive";
472
473 m_modelGuidelineAfter->setLineWidthActive (lineWidth);
474 updateControls();
475 updatePreview();
476}
477
478void DlgSettingsGuideline::slotLineWidthInactive (int lineWidth)
479{
480 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::slotLineWidthInactive";
481
482 m_modelGuidelineAfter->setLineWidthInactive (lineWidth);
483 updateControls();
484 updatePreview();
485}
486
487void DlgSettingsGuideline::slotWhatsThis ()
488{
489 QWhatsThis::enterWhatsThisMode();
490}
491
492void DlgSettingsGuideline::updateControls ()
493{
494 enableOk (true);
495}
496
497void DlgSettingsGuideline::updatePreview()
498{
499 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGuideline::updatePreview";
500
501 enableOk (true);
502 updatePreviewGeometry ();
503 updatePreviewStyle ();
504}
505
506void DlgSettingsGuideline::updatePreviewGeometry()
507{
508 // Screen bounds use main QGraphicsScene since that is synchronized with the main transformation used below
509 int width = mainWindow().scene().width();
510 int height = mainWindow().scene().height();
511 QPointF posGraphTL, posGraphTR, posGraphBL, posGraphBR;
513 posGraphTL);
515 posGraphTR);
516 mainWindow().transformation().transformScreenToRawGraph (QPointF (0, height),
517 posGraphBL);
518 mainWindow().transformation().transformScreenToRawGraph(QPointF (width, height),
519 posGraphBR);
520
521 double xMin = qMin (qMin (qMin (posGraphTL.x(), posGraphTR.x()), posGraphBL.x()), posGraphBR.x());
522 double yMin = qMin (qMin (qMin (posGraphTL.y(), posGraphTR.y()), posGraphBL.y()), posGraphBR.y());
523 double xMax = qMax (qMax (qMax (posGraphTL.x(), posGraphTR.x()), posGraphBL.x()), posGraphBR.x());
524 double yMax = qMax (qMax (qMax (posGraphTL.y(), posGraphTR.y()), posGraphBL.y()), posGraphBR.y());
525
526 if (cmdMediator().document().modelCoords().coordsType() == COORDS_TYPE_CARTESIAN) {
527
528 // Update cartesian items
529 QPointF posClickScreen;
530 updatePreviewGeometryGuidelineCartesian (width,
531 height,
532 posClickScreen,
533 xMin,
534 xMax,
535 yMin,
536 yMax);
537 updatePreviewGeometryCirclePolar (posClickScreen);
538 updatePreviewGeometryCentipedeCartesian (posClickScreen,
539 xMin,
540 xMax,
541 yMin,
542 yMax);
543
544 } else {
545
546 // Update polar items
547 QPointF posClickScreen;
548 QPointF posOriginScreen = updatePreviewGeometryGuidelinePolar (width,
549 height,
550 posClickScreen);
551 updatePreviewGeometryCirclePolar (posClickScreen);
552 updatePreviewGeometryCentipedePolar (posOriginScreen,
553 posClickScreen);
554
555 }
556}
557
558void DlgSettingsGuideline::updatePreviewGeometryCentipedeCartesian (const QPointF &posClickScreen,
559 double /* xMin */,
560 double /* xMax */,
561 double /* yMin */,
562 double /* yMax */)
563{
564 CentipedeEndpointsCartesian endpoints (*m_modelGuidelineAfter,
565 mainWindow().transformation (),
566 posClickScreen);
567
568 QPointF posStartX = endpoints.posScreenConstantXForLowY (m_modelGuidelineAfter->creationCircleRadius());
569 QPointF posStopX = endpoints.posScreenConstantXForHighY (m_modelGuidelineAfter->creationCircleRadius());
570 QPointF posStartY = endpoints.posScreenConstantYForLowX (m_modelGuidelineAfter->creationCircleRadius());
571 QPointF posStopY = endpoints.posScreenConstantYForHighX (m_modelGuidelineAfter->creationCircleRadius());
572
573 safeSetLine (m_itemCentipedeXTActive,
574 posStartX,
575 posStopX);
576 safeSetLine (m_itemCentipedeYActive,
577 posStartY,
578 posStopY);
579}
580
581void DlgSettingsGuideline::updatePreviewGeometryCentipedePolar (const QPointF &posOriginScreen,
582 const QPointF &posClickScreen)
583{
584 CentipedeEndpointsPolar endpoints (cmdMediator().document().modelCoords(),
585 *m_modelGuidelineAfter,
586 mainWindow().transformation(),
587 posClickScreen,
588 posOriginScreen);
589
590 // Get low and high constant theta points
591 QPointF posRadialLow, posRadialHigh;
592 endpoints.posScreenConstantTForRHighLow (m_modelGuidelineAfter->creationCircleRadius(),
593 posRadialLow,
594 posRadialHigh);
595
596 // Get radius that is in same rangea as screen
597 QPointF posClickGraph;
599 posClickGraph);
600 double rGraph = posClickGraph.y();
601
602 // Get basis vectors in graph coordinates
603 QPointF posScreen0, posScreen90;
604 mainWindow().transformation().transformRawGraphToScreen (QPointF (0, rGraph),
605 posScreen0);
606 mainWindow().transformation().transformRawGraphToScreen (QPointF (90, rGraph),
607 posScreen90);
608
609 // Ellipse
610 double angleRotation;
611 QRectF rectBounding;
612 CentipedeDebugPolar debugPolar;
613 endpoints.ellipseScreenConstantRForTHighLowAngles (mainWindow().transformation(),
614 posClickScreen,
615 angleRotation,
616 rectBounding,
617 debugPolar);
618
619 // Get low and high constant radius points
620 QPointF posTangentialLow, posTangentialHigh;
621 endpoints.posScreenConstantRHighLow (m_modelGuidelineAfter->creationCircleRadius(),
622 posTangentialLow,
623 posTangentialHigh);
624
625 debugPolar.display (*m_scenePreviewActive,
626 cmdMediator().document().modelCoords(),
627 mainWindow().transformation());
628
629 //safeSetLine (m_itemCentipedeXTActive,
630 // posRadialLow,
631 // posRadialHigh);
632 //safeSetEllipseGeometry (m_itemCentipedeRActive,
633 // rectBounding,
634 // angleRotation,
635 // angleLow,
636 // angleHigh);
637}
638
639void DlgSettingsGuideline::updatePreviewGeometryCirclePolar (const QPointF &posClickScreen)
640{
641 safeSetRect (m_itemCentipedeCircleActive,
642 QRectF (posClickScreen.x() - m_modelGuidelineAfter->creationCircleRadius(),
643 posClickScreen.y() - m_modelGuidelineAfter->creationCircleRadius(),
644 2 * m_modelGuidelineAfter->creationCircleRadius(),
645 2 * m_modelGuidelineAfter->creationCircleRadius()));
646}
647
648void DlgSettingsGuideline::updatePreviewGeometryGuidelineCartesian (double width,
649 double height,
650 QPointF &posClickScreen,
651 double xMin,
652 double xMax,
653 double yMin,
654 double yMax)
655{
656 // Arbitrarily put virtual click in first quadrant. Since lines are horizontal
657 // and vertical through center there should be no overlap
658 posClickScreen = QPointF (0.75 * width,
659 0.25 * height);
660
661 // Show one vertical line and one horizontal line with both approximately through center of screen
662 double xMid = (xMin + xMax) / 2.0;
663 double yMid = (yMin + yMax) / 2.0;
664
665 QPointF posLeft, posRight, posTop, posBottom;
666 mainWindow().transformation().transformRawGraphToScreen (QPointF (xMin, yMid),
667 posLeft);
668 mainWindow().transformation().transformRawGraphToScreen (QPointF (xMax, yMid),
669 posRight);
670 mainWindow().transformation().transformRawGraphToScreen (QPointF (xMid, yMin),
671 posTop);
672 mainWindow().transformation().transformRawGraphToScreen (QPointF (xMid, yMax),
673 posBottom);
674
675 safeSetLine (m_itemGuidelineXTActive,
676 posBottom,
677 posTop);
678 safeSetLine (m_itemGuidelineYActive,
679 posLeft,
680 posRight);
681 safeSetLine (m_itemGuidelineXTInactive,
682 posBottom,
683 posTop);
684 safeSetLine (m_itemGuidelineYInactive,
685 posLeft,
686 posRight);
687}
688
689QPointF DlgSettingsGuideline::updatePreviewGeometryGuidelinePolar (double width,
690 double height,
691 QPointF &posClickScreen)
692{
693 // Show horizontal line and circle/ellipse
694
695 // Compute ellipse parameters first so we can plae posClickScreen away from the theta guideline
696 QPointF posCenter, posLeft (0, height / 2), posRight (width, height / 2), posTop (width / 2, 0), posBottom (width / 2, height);
698 posCenter);
699
700 double rReference = radiusOfClosestSide (posLeft,
701 posRight,
702 posTop,
703 posBottom); // Use a little less than the distance from origin to closest side
704
705 GuidelineProjectorConstantT projectorT;
706 GuidelineProjectorConstantR projectorR;
707 QLineF line = projectorT.fromCoordinateT (mainWindow().transformation(),
708 m_viewPreviewActive->sceneRect(),
710 EllipseParameters ellipseParameters = projectorR.fromCoordinateR (mainWindow().transformation(),
711 m_viewPreviewActive->sceneRect (),
712 rReference);
713
714 double a = ellipseParameters.a();
715 double b = ellipseParameters.b();
716
717 // Compute posClickScreen. Arbitrariliy pick 90 degrees off from guideline along 0 degrees, to distinguish the two radial lines
718 double angleClickScreen = M_PI / 2.0;
719 mainWindow().transformation().transformRawGraphToScreen (QPointF (qRadiansToDegrees (angleClickScreen),
720 rReference / 2.0),
721 posClickScreen);
722
723 safeSetLine (m_itemGuidelineXTActive,
724 line.p1(),
725 line.p2());
726 safeSetRect (m_itemGuidelineRActive,
727 QRectF (- QPointF (a, b),
728 + QPointF (a, b)));
729 safeSetRotation (m_itemGuidelineRActive,
730 -1.0 * qRadiansToDegrees (angleClickScreen));
731 safeSetPos (m_itemGuidelineRActive,
732 posCenter);
733 safeSetLine (m_itemGuidelineXTInactive,
734 line.p1(),
735 line.p2());
736 safeSetRect (m_itemGuidelineRInactive,
737 QRectF (- QPointF (a, b),
738 + QPointF (a, b)));
739 safeSetRotation (m_itemGuidelineRInactive,
740 -1.0 * qRadiansToDegrees (angleClickScreen));
741 safeSetPos (m_itemGuidelineRInactive,
742 posCenter);
743
744 return posCenter;
745}
746
747void DlgSettingsGuideline::updatePreviewStyle ()
748{
749 // Skip calls during initialization before graphics items have been created
750 safeSetLineStyle (m_itemGuidelineXTActive,
751 m_modelGuidelineAfter->lineWidthActive());
752 safeSetLineStyle (m_itemGuidelineYActive,
753 m_modelGuidelineAfter->lineWidthActive());
754 safeSetEllipseStyle (m_itemGuidelineRActive,
755 m_modelGuidelineAfter->lineWidthActive());
756 safeSetLineStyle (m_itemGuidelineXTInactive,
757 m_modelGuidelineAfter->lineWidthInactive());
758 safeSetLineStyle (m_itemGuidelineYInactive,
759 m_modelGuidelineAfter->lineWidthInactive());
760 safeSetEllipseStyle (m_itemGuidelineRInactive,
761 m_modelGuidelineAfter->lineWidthInactive());
762
763 safeSetLineStyle (m_itemCentipedeXTActive,
764 m_modelGuidelineAfter->lineWidthActive());
765 safeSetLineStyle (m_itemCentipedeYActive,
766 m_modelGuidelineAfter->lineWidthActive());
767 safeSetEllipseStyle (m_itemCentipedeRActive,
768 m_modelGuidelineAfter->lineWidthActive());
769}
ColorPalette
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13
const int MINIMUM_HEIGHT
const int MINIMUM_PREVIEW_WIDTH
const double T_REFERENCE
const int MINIMUM_DIALOG_WIDTH_GUIDELINES
const double RADIANS_TO_TICS
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
log4cpp::Category * mainCat
Definition Logger.cpp:14
void display(QGraphicsScene &scene, const DocumentModelCoords &modelCoords, const Transformation &transformation)
Display member variable values on scene.
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Command for DlgSettingsGuideline.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void addPixmap(QGraphicsScene &scene, const QPixmap &pixmap)
Adds pixmap to the scene.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
DlgSettingsGuideline(MainWindow &mainWindow)
Single constructor.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual void handleOk()
Process slotOk.
Model for managing the coordinate values corresponding Guidelines.
QPixmap pixmap() const
Return the image that is being digitized.
Definition Document.cpp:843
double b() const
Get method for b.
double a() const
Get method for a.
EllipseParameters fromCoordinateR(const Transformation &transformation, const QRectF &sceneRect, double rGraph)
Return line through y in graph coordinates.
QLineF fromCoordinateT(const Transformation &transformation, const QRectF &sceneRect, double tGraph)
Return line through theta in graph coordinates.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Transformation transformation() const
Return read-only copy of transformation.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
Definition ViewPreview.h:15
@ VIEW_ASPECT_RATIO_VARIABLE
Definition ViewPreview.h:22
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18