Isis 3 Programmer Reference
SpecialPixelTool.cpp
1#include "SpecialPixelTool.h"
2
3#include <QCheckBox>
4#include <QColorDialog>
5#include <QDialog>
6#include <QHBoxLayout>
7#include <QLabel>
8#include <QMenu>
9#include <QPainter>
10#include <QPalette>
11#include <QPixmap>
12#include <QPushButton>
13#include <QToolBar>
14#include <QToolButton>
15#include <QVBoxLayout>
16
17#include "FileName.h"
18#include "MainWindow.h"
19#include "MdiCubeViewport.h"
20#include "Stretch.h"
21#include "CubeStretch.h"
22#include "Workspace.h"
23
24namespace Isis {
32 // Create the SpecialPixel window
33 p_parent = parent;
34
35 p_dialog = new QDialog(parent);
36 p_dialog->setWindowTitle("Special Pixel Tool");
37 p_dialog->setSizeGripEnabled(true);
39 p_spWindow->setMinimumSize(492, 492);
40 p_spWindow->installEventFilter(this);
41
42 QWidget *buttons = new QWidget(p_dialog);
43 QWidget *colors = new QWidget(p_dialog);
44 QWidget *labels = new QWidget(p_dialog);
45 QWidget *defaults = new QWidget(p_dialog);
46 QWidget *main = new QWidget(p_dialog);
47
48 QVBoxLayout *layout = new QVBoxLayout();
49 layout->addWidget(defaults, 0);
50 layout->addWidget(main, 0);
51 layout->addWidget(buttons, 0);
52 p_dialog->setLayout(layout);
53
54 QPushButton *ok = new QPushButton("Ok", buttons);
55 ok->setShortcut(Qt::Key_Enter);
56 connect(ok, SIGNAL(released()), this, SLOT(apply()));
57 connect(ok, SIGNAL(released()), p_dialog, SLOT(hide()));
58
59 QPushButton *apply = new QPushButton("Apply", buttons);
60 connect(apply, SIGNAL(released()), this, SLOT(apply()));
61
62 QPushButton *cancel = new QPushButton("Cancel", buttons);
63 connect(cancel, SIGNAL(released()), p_dialog, SLOT(hide()));
64
65 QPushButton *defaultBlackWhite = new QPushButton("Default B&W", defaults);
66 connect(defaultBlackWhite, SIGNAL(released()), this, SLOT(defaultBW()));
67
68 QPushButton *defaultColor = new QPushButton("Default Color", defaults);
69 connect(defaultColor, SIGNAL(released()), this, SLOT(defaultColor()));
70
71 QHBoxLayout *hlayout = new QHBoxLayout();
72 hlayout->addWidget(ok);
73 hlayout->addWidget(apply);
74 hlayout->addWidget(cancel);
75 // hlayout->addStretch(1);
76 buttons->setLayout(hlayout);
77
78 QHBoxLayout *h2layout = new QHBoxLayout();
79 h2layout->addWidget(defaultBlackWhite);
80 h2layout->addWidget(defaultColor);
81 defaults->setLayout(h2layout);
82
83 p_nullColor = new QToolButton(p_dialog);
84 connect(p_nullColor, SIGNAL(released()), this, SLOT(setNullColor()));
85 QSize *size = new QSize(25, 25);
86 QLabel *nullLabel = new QLabel("Null");
87 p_nullColor->setFixedSize(*size);
88
89 p_lisColor = new QToolButton(p_dialog);
90 connect(p_lisColor, SIGNAL(released()), this, SLOT(setLisColor()));
91 QLabel *lisLabel = new QLabel("Low Instrument Saturation");
92 p_lisColor->setFixedSize(*size);
93
94 p_lrsColor = new QToolButton(p_dialog);
95 connect(p_lrsColor, SIGNAL(released()), this, SLOT(setLrsColor()));
96 QLabel *lrsLabel = new QLabel("Low Representation Saturation");
97 p_lrsColor->setFixedSize(*size);
98
99 p_ldsColor = new QToolButton(p_dialog);
100 connect(p_ldsColor, SIGNAL(released()), this, SLOT(setLdsColor()));
101 QLabel *ldsLabel = new QLabel("Low Display Saturation");
102 p_ldsColor->setFixedSize(*size);
103
104 p_hisColor = new QToolButton(p_dialog);
105 connect(p_hisColor, SIGNAL(released()), this, SLOT(setHisColor()));
106 QLabel *hisLabel = new QLabel("High Instrument Saturation");
107 p_hisColor->setFixedSize(*size);
108
109 p_hrsColor = new QToolButton(p_dialog);
110 connect(p_hrsColor, SIGNAL(released()), this, SLOT(setHrsColor()));
111 QLabel *hrsLabel = new QLabel("High Representation Saturation");
112 p_hrsColor->setFixedSize(*size);
113
114 p_hdsColor = new QToolButton(p_dialog);
115 connect(p_hdsColor, SIGNAL(released()), this, SLOT(setHdsColor()));
116 QLabel *hdsLabel = new QLabel("High Display Saturation");
117 p_hdsColor->setFixedSize(*size);
118
119 p_bgColor = new QToolButton(p_dialog);
120 connect(p_bgColor, SIGNAL(released()), this, SLOT(setBgColor()));
121 QLabel *bgLabel = new QLabel("Background");
122 p_bgColor->setFixedSize(*size);
123
124 connect(this, SIGNAL(setDefaultColors()), this, SLOT(defaultBW()));
125 emit setDefaultColors();
126
127 QVBoxLayout *vlayout = new QVBoxLayout();
128 vlayout->addWidget(nullLabel);
129 vlayout->addWidget(lisLabel);
130 vlayout->addWidget(hisLabel);
131 vlayout->addWidget(lrsLabel);
132 vlayout->addWidget(hrsLabel);
133 vlayout->addWidget(ldsLabel);
134 vlayout->addWidget(hdsLabel);
135 vlayout->addWidget(bgLabel);
136 labels->setLayout(vlayout);
137
138 QVBoxLayout *v2layout = new QVBoxLayout();
139 v2layout->addWidget(p_nullColor);
140 v2layout->addWidget(p_lisColor);
141 v2layout->addWidget(p_hisColor);
142 v2layout->addWidget(p_lrsColor);
143 v2layout->addWidget(p_hrsColor);
144 v2layout->addWidget(p_ldsColor);
145 v2layout->addWidget(p_hdsColor);
146 v2layout->addWidget(p_bgColor);
147 colors->setLayout(v2layout);
148
149 QHBoxLayout *mainlayout = new QHBoxLayout();
150 mainlayout->addWidget(colors);
151 mainlayout->addWidget(labels);
152 main->setLayout(mainlayout);
153
154 // Create the action to bring up the SpecialPixel window
155 p_action = new QAction(parent);
156 //p_action->setShortcut(Qt::CTRL+Qt::Key_C);
157 p_action->setText("&Special Pixel Tool ...");
158 p_action->setIcon(QPixmap(toolIconDir() + "/colorize.png"));
159 p_action->setToolTip("SpecialPixelTool");
160 QString text =
161 "<b>Function:</b> Opens a window that allows you to chose what color to \
162 display each different type of special pixel \
163 <p><b>Shortcut:</b> Ctrl+C</p>";
164 p_action->setWhatsThis(text);
165 p_action->setEnabled(false);
166 connect(p_action, SIGNAL(triggered()), p_dialog, SLOT(show()));
167
168 readSettings();
169 }
170
171
179 menu->addAction(p_action);
180 }
181
182
190 perm->addAction(p_action);
191 }
192
193
199 Tool::addTo(ws);
200 connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
201 this, SLOT(apply()));
202 }
203
204
210 for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
211 MdiCubeViewport *cvp = (*(cubeViewportList()))[i];
212
213 // Get the Stretch objects from the cubeViewport
214 CubeStretch redStretch = cvp->redStretch();
215 CubeStretch greenStretch = cvp->greenStretch();
216 CubeStretch blueStretch = cvp->blueStretch();
217
218 // Apply selected null color
219 QPalette palette = p_nullColor->palette();
220 QColor nullColor = palette.color(QPalette::Button);
221 int r, g, b;
222 nullColor.getRgb(&r, &g, &b);
223 redStretch.SetNull(r);
224 greenStretch.SetNull(g);
225 blueStretch.SetNull(b);
226
227 // Apply selected lis
228 palette = p_lisColor->palette();
229 QColor lisColor = palette.color(QPalette::Button);
230 lisColor.getRgb(&r, &g, &b);
231 redStretch.SetLis(r);
232 greenStretch.SetLis(g);
233 blueStretch.SetLis(b);
234
235 // Apply selected lrs
236 palette = p_lrsColor->palette();
237 QColor lrsColor = palette.color(QPalette::Button);
238 lrsColor.getRgb(&r, &g, &b);
239 redStretch.SetLrs(r);
240 greenStretch.SetLrs(g);
241 blueStretch.SetLrs(b);
242
243 // Apply selected lds
244 palette = p_ldsColor->palette();
245 QColor ldsColor = palette.color(QPalette::Button);
246 ldsColor.getRgb(&r, &g, &b);
247 redStretch.SetMinimum(r);
248 greenStretch.SetMinimum(g);
249 blueStretch.SetMinimum(b);
250
251 // Apply selected his
252 palette = p_hisColor->palette();
253 QColor hisColor = palette.color(QPalette::Button);
254 hisColor.getRgb(&r, &g, &b);
255 redStretch.SetHis(r);
256 greenStretch.SetHis(g);
257 blueStretch.SetHis(b);
258
259 // Apply selected hrs
260 palette = p_hrsColor->palette();
261 QColor hrsColor = palette.color(QPalette::Button);
262 hrsColor.getRgb(&r, &g, &b);
263 redStretch.SetHrs(r);
264 greenStretch.SetHrs(g);
265 blueStretch.SetHrs(b);
266
267 // Apply selected hds
268 palette = p_hdsColor->palette();
269 QColor hdsColor = palette.color(QPalette::Button);
270 hdsColor.getRgb(&r, &g, &b);
271 redStretch.SetMaximum(r);
272 greenStretch.SetMaximum(g);
273 blueStretch.SetMaximum(b);
274
275 // Apply selected background
276 palette = p_bgColor->palette();
277 QColor bgColor = palette.color(QPalette::Button);
278 bgColor.getRgb(&r, &g, &b);
279
280 cvp->setBackground(bgColor);
281 cvp->stretchRed(redStretch);
282 cvp->stretchGreen(greenStretch);
283 cvp->stretchBlue(blueStretch);
284
285 //If any of the defaults changed, make sure to write them
286 if(p_color) {
287 p_nullDefault = nullColor;
288 p_lisDefault = lisColor;
289 p_lrsDefault = lrsColor;
290 p_ldsDefault = ldsColor;
291 p_hisDefault = hisColor;
292 p_hrsDefault = hrsColor;
293 p_hdsDefault = hdsColor;
294 p_bgDefault = bgColor;
296 }
297 }
298 }
299
300
308
309
317
318
326
327
335
336
344
345
353
354
362
363 void SpecialPixelTool::setBgColor() {
365 }
366
373 void SpecialPixelTool::setColor(QToolButton *button) {
374 // Let the user pick a color
375 QColor color = QColorDialog::getColor();
376
377 // Set the color if they didnt cancel out of the window
378 if(color.isValid()) {
379 QPalette *palette = new QPalette();
380 palette->setColor(QPalette::Button, color);
381 button->setPalette(*palette);
382 }
383
384 }
385
386
392 p_color = false;
393 QPalette *palette = new QPalette();
394 palette->setColor(QPalette::Button, Qt::black);
395 p_nullColor->setPalette(*palette);
396 p_lisColor->setPalette(*palette);
397 p_lrsColor->setPalette(*palette);
398 p_ldsColor->setPalette(*palette);
399 p_bgColor->setPalette(*palette);
400
401 palette->setColor(QPalette::Button, Qt::white);
402 p_hisColor->setPalette(*palette);
403 p_hrsColor->setPalette(*palette);
404 p_hdsColor->setPalette(*palette);
405 }
406
407
413 p_color = true;
414 QPalette *palette = new QPalette();
415 palette->setColor(QPalette::Button, p_nullDefault);
416 p_nullColor->setPalette(*palette);
417
418 palette->setColor(QPalette::Button, p_lisDefault);
419 p_lisColor->setPalette(*palette);
420
421 palette->setColor(QPalette::Button, p_lrsDefault);
422 p_lrsColor->setPalette(*palette);
423
424 palette->setColor(QPalette::Button, p_ldsDefault);
425 p_ldsColor->setPalette(*palette);
426
427 palette->setColor(QPalette::Button, p_hisDefault);
428 p_hisColor->setPalette(*palette);
429
430 palette->setColor(QPalette::Button, p_hrsDefault);
431 p_hrsColor->setPalette(*palette);
432
433 palette->setColor(QPalette::Button, p_hdsDefault);
434 p_hdsColor->setPalette(*palette);
435
436 palette->setColor(QPalette::Button, p_bgDefault);
437 p_bgColor->setPalette(*palette);
438 }
439
440
446 if(cubeViewport() == NULL) {
447 p_action->setEnabled(false);
448 }
449 else {
450 p_action->setEnabled(true);
451 }
452 }
453
454
461 /*Now read the settings that are specific to this window.*/
462 QString appName = p_parent->windowTitle();
463
464 /*Now read the settings that are specific to this window.*/
465 QString instanceName = p_dialog->windowTitle();
466
467 FileName config("$HOME/.Isis/" + appName + "/" + instanceName + ".config");
468 p_settings = new QSettings(config.expanded(), QSettings::NativeFormat);
469
470 //For each special pixel value, if it exists set it, otherwise set
471 //it to the system defaults.
472
473 //Default value for Null
474 if(p_settings->value("defaultNull", 1).toInt() == 0) {
475 p_nullDefault = p_settings->value("defaultNull", 1).value<QColor>();
476 }
477 else {
478 p_nullDefault = Qt::blue;
479 }
480
481 //Default value for Lis
482 if(p_settings->value("defaultLis", 1).toInt() == 0) {
483 p_lisDefault = p_settings->value("defaultLis", 1).value<QColor>();
484 }
485 else {
486 p_lisDefault = Qt::cyan;
487 }
488
489 //Default value for Lrs
490 if(p_settings->value("defaultLrs", 1).toInt() == 0) {
491 p_lrsDefault = p_settings->value("defaultLrs", 1).value<QColor>();
492 }
493 else {
494 p_lrsDefault = Qt::yellow;
495 }
496
497 //Default value for Lds
498 if(p_settings->value("defaultLds", 1).toInt() == 0) {
499 p_ldsDefault = p_settings->value("defaultLds", 1).value<QColor>();
500 }
501 else {
502 p_ldsDefault = Qt::black;
503 }
504
505 //Default value for His
506 if(p_settings->value("defaultHis", 1).toInt() == 0) {
507 p_hisDefault = p_settings->value("defaultHis", 1).value<QColor>();
508 }
509 else {
510 p_hisDefault = Qt::magenta;
511 }
512
513 //Default value for Hrs
514 if(p_settings->value("defaultHrs", 1).toInt() == 0) {
515 p_hrsDefault = p_settings->value("defaultHrs", 1).value<QColor>();
516 }
517 else {
518 p_hrsDefault = Qt::green;
519 }
520
521 //Default value for Hds
522 if(p_settings->value("defaultHds", 1).toInt() == 0) {
523 p_hdsDefault = p_settings->value("defaultHds", 1).value<QColor>();
524 }
525 else {
526 p_hdsDefault = Qt::white;
527 }
528
529 //Default value for Bg
530 if(p_settings->value("defaultBg", 1).toInt() == 0) {
531 p_bgDefault = p_settings->value("defaultBg", 1).value<QColor>();
532 }
533 else {
534 p_bgDefault = Qt::black;
535 }
536 }
537
538
545 QString appName = p_parent->windowTitle();
546
547 /*Now read the settings that are specific to this window.*/
548 QString instanceName = p_dialog->windowTitle();
549
550 //Write all of the special pixel value colors
551 FileName config("$HOME/.Isis/" + appName + "/" + instanceName + ".config");
552 QSettings settings(config.expanded(), QSettings::NativeFormat);
553 settings.setValue("defaultNull", p_nullDefault);
554 settings.setValue("defaultLis", p_lisDefault);
555 settings.setValue("defaultLrs", p_lrsDefault);
556 settings.setValue("defaultLds", p_ldsDefault);
557 settings.setValue("defaultHis", p_hisDefault);
558 settings.setValue("defaultHrs", p_hrsDefault);
559 settings.setValue("defaultHds", p_hdsDefault);
560 settings.setValue("defaultBg", p_bgDefault);
561 }
562}
Stores stretch information for a cube.
Definition CubeStretch.h:27
File name manipulation and expansion.
Definition FileName.h:100
Cube display widget for certain Isis MDI applications.
QToolButton * p_lrsColor
Low representation saturation Button.
void setHrsColor()
Sets the color for Hrs pixels.
void updateTool()
Updates special pixel tool.
void setNullColor()
Sets the color for null pixels.
void addToPermanent(QToolBar *perm)
Adds the tool to the permanent tool bar.
QToolButton * p_hrsColor
High representation saturation Button.
QSettings * p_settings
< Settings
QToolButton * p_bgColor
Background color Button.
void defaultColor()
Reset the default color colors.
void setHisColor()
Sets the color for His pixels.
QDialog * p_dialog
Dialog box.
QToolButton * p_ldsColor
Low Button.
void addTo(QMenu *menu)
Adds the tool to the given menu.
SpecialPixelTool(QWidget *parent)
SpecialPixelTool constructor.
QToolButton * p_hisColor
High instrument saturation Button.
QWidget * p_spWindow
Window widget.
void writeSettings()
This methods writes the default special pixel values to a config file that will be read by the readSe...
QColor p_ldsDefault
Color chosen for pixels.
void apply()
Applies the colors picked for the special pixels.
QColor p_bgDefault
Color chosen for pixels.
void setLisColor()
Sets the color for Lis pixels.
void readSettings()
This method reads in the default special pixel value colors from a config file.
void setDefaultColors()
Emitted when the default colors are reset.
void setColor(QToolButton *button)
Gets the selected color from the color dialog.
QColor p_hdsDefault
Color chosen for pixels.
QWidget * p_parent
Parent widget.
void setHdsColor()
Sets the color for Hds pixels.
void setLrsColor()
Sets the color for Lrs pixels.
QToolButton * p_hdsColor
High Button.
QColor p_hisDefault
Color chosen for high instrument saturation pixels.
QAction * p_action
Special Pixel Tool's action.
QToolButton * p_nullColor
Null Button.
void setLdsColor()
Sets the color for Lds pixels.
QColor p_nullDefault
Color chosen for null pixels.
void defaultBW()
Reset the default black/white colors.
QToolButton * p_lisColor
Low instrument saturation Button.
QColor p_lisDefault
Color chosen for low instrument saturation pixels.
QColor p_hrsDefault
Color chosen for high representation saturation pixels.
QColor p_lrsDefault
Color chosen for Low representation saturation pixels.
void SetNull(const double value)
Sets the mapping for NULL pixels.
Definition Stretch.h:94
void SetHrs(const double value)
Sets the mapping for HRS pixels.
Definition Stretch.h:138
void SetHis(const double value)
Sets the mapping for HIS pixels.
Definition Stretch.h:127
void SetLis(const double value)
Sets the mapping for LIS pixels.
Definition Stretch.h:105
void SetLrs(const double value)
Sets the mapping for LRS pixels.
Definition Stretch.h:116
Base class for the Qisis tools.
Definition Tool.h:67
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition Tool.cpp:78
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition Tool.cpp:390
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition Tool.h:197
QString toolIconDir() const
returns the path to the icon directory.
Definition Tool.h:113
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16