annotate libgui/graphics/annotation-dialog.cc @ 20354:227d582fa300 stable

build: Sort generated PKG_ADD contents consistently * libinterp/mk-pkg-add: Set LC_COLLATE=C when sorting for consistent output.
author Mike Miller <mtmiller@octave.org>
date Fri, 10 Jul 2015 01:10:30 -0400
parents 6fe746def1aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
1 /*
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
2
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
3 Copyright (C) 2015 John Donoghue
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
4
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
5 This file is part of Octave.
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
6
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
10 option) any later version.
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
11
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
15 for more details.
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
16
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
20
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
21 */
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
22
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
24 #include <config.h>
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
25 #endif
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
26
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
27 #include "annotation-dialog.h"
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
28 #include "ui-annotation-dialog.h"
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
29
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
30 #include "QtHandlesUtils.h"
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
31
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
32 #include "resource-manager.h"
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
33
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
34 #include <QColorDialog>
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
35 #include <QPushButton>
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
36 #include <QPalette>
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
37
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
38 using namespace QtHandles;
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
39
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
40 annotation_dialog::annotation_dialog (QWidget *p, const octave_value_list &pr):
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
41 QDialog (p), ui (new Ui::annotation_dialog)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
42 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
43 props = pr;
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
44
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
45 init ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
46 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
47
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
48 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
49 annotation_dialog::init ()
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
50 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
51 ui->setupUi (this);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
52
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
53 QSettings *settings = resource_manager::get_settings ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
54
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
55 // restore last geometry
20281
6fe746def1aa Also load settings and translations in --no-gui mode (bugs #44222 and #45199)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20216
diff changeset
56 if (settings)
6fe746def1aa Also load settings and translations in --no-gui mode (bugs #44222 and #45199)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20216
diff changeset
57 restoreGeometry (settings->value("annotation/geometry").toByteArray ());
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
58
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
59 // connect signals
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
60 connect (ui->button_box, SIGNAL (clicked (QAbstractButton *)),
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
61 this, SLOT (button_clicked (QAbstractButton *)));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
62
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
63
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
64 connect (ui->edit_string, SIGNAL (textChanged (const QString&)),
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
65 this, SLOT (edit_string_changed (const QString&)));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
66
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
67 connect (ui->btn_color, SIGNAL (clicked ()),
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
68 this, SLOT (prompt_for_color ()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
69
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
70 connect (ui->btn_background_color, SIGNAL (clicked ()),
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
71 this, SLOT (prompt_for_color ()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
72
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
73 connect (ui->btn_edge_color, SIGNAL (clicked ()),
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
74 this, SLOT (prompt_for_color ()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
75
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
76 // set gui element to default values
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
77 ui->cb_fit_box_to_text->setChecked (true);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
78 ui->cb_horz_align->setCurrentIndex ( ui->cb_horz_align->findText("left") );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
79 ui->cb_vert_align->setCurrentIndex ( ui->cb_vert_align->findText("middle") );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
80
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
81 // set gui elements to any values from input properties
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
82 set_gui_props ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
83 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
84
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
85 annotation_dialog::~annotation_dialog ()
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
86 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
87 delete ui;
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
88 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
89
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
90 // internal slots
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
91
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
92 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
93 annotation_dialog::button_clicked (QAbstractButton *button)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
94 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
95 QDialogButtonBox::ButtonRole button_role = ui->button_box->buttonRole (button);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
96
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
97 QSettings *settings = resource_manager::get_settings ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
98
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
99 // save position
20281
6fe746def1aa Also load settings and translations in --no-gui mode (bugs #44222 and #45199)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20216
diff changeset
100 if (settings)
6fe746def1aa Also load settings and translations in --no-gui mode (bugs #44222 and #45199)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20216
diff changeset
101 settings->setValue ("annotation/geometry",saveGeometry ());
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
102
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
103 if (button_role == QDialogButtonBox::ApplyRole ||
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
104 button_role == QDialogButtonBox::AcceptRole)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
105 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
106 get_gui_props ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
107 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
108
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
109 if (button_role == QDialogButtonBox::RejectRole ||
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
110 button_role == QDialogButtonBox::AcceptRole)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
111 close ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
112 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
113
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
114 octave_value_list
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
115 annotation_dialog::get_properties () const
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
116 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
117 return props;
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
118 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
119
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
120 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
121 annotation_dialog::get_gui_props ()
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
122 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
123 // set props to the values of the gui
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
124 props = octave_value_list ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
125
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
126 Matrix position(1,4);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
127 position(0) = ui->sb_x->value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
128 position(1) = ui->sb_y->value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
129 position(2) = ui->sb_width->value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
130 position(3) = ui->sb_height->value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
131 props.append (ovl ("textbox", position));
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
132
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
133 props.append (ovl ("string", ui->edit_string->text ().toStdString ()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
134 props.append (ovl ("fitboxtotext", ui->cb_fit_box_to_text->isChecked() ? "on" : "off" ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
135 props.append (ovl ("units", ui->cb_units->currentText ().toStdString () ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
136 props.append (ovl ("horizontalalignment", ui->cb_horz_align->currentText ().toStdString () ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
137 props.append (ovl ("verticalalignment", ui->cb_vert_align->currentText ().toStdString () ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
138 props.append (ovl ("fontname", ui->cb_font_name->currentText ().toStdString()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
139 props.append (ovl ("fontsize", ui->sb_font_size->value ()));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
140 props.append (ovl ("fontweight", ui->cb_font_bold->isChecked() ? "bold" : "normal" ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
141 props.append (ovl ("fontangle", ui->cb_font_italic->isChecked() ? "italic" : "normal" ));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
142 props.append (ovl ("color", Utils::toRgb (ui->btn_color->palette ().color (QPalette::Button))));
20144
5a4717862648 annotation-dialog: default linestyle to none
John Donoghue <john.donoghue@ieee.org>
parents: 20130
diff changeset
143 props.append (ovl ("linestyle", ui->cb_line_style->currentText ().toStdString ()));
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
144 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
145
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
146 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
147 annotation_dialog::set_gui_props ()
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
148 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
149 // set the gui to the values from the props
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
150 octave_idx_type len = props.length ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
151
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
152 for (int i=0; i<len/2; i++)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
153 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
154 std::string name = props(i*2).string_value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
155
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
156 if (name == "textbox")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
157 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
158 Matrix position = props(2*i +1).matrix_value ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
159 int nels = position.numel();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
160 if (nels >= 2)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
161 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
162 ui->sb_x->setValue (position(0));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
163 ui->sb_y->setValue (position(1));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
164 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
165 else
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
166 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
167 ui->sb_x->setValue (0);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
168 ui->sb_y->setValue (0);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
169 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
170 if (nels >= 4)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
171 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
172 ui->sb_width->setValue (position(2));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
173 ui->sb_height->setValue (position(3));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
174 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
175 else
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
176 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
177 ui->sb_width->setValue (position(2));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
178 ui->sb_height->setValue (position(3));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
179 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
180 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
181 else if (name == "string")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
182 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
183 // FIXME: handle if is array of strings ?
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
184 ui->edit_string->setText (props(2*i +1).string_value ().c_str ());
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
185 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
186 else if (name == "fitboxtotext")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
187 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
188 ui->cb_fit_box_to_text->setChecked ( props(1*i +1).string_value () == "on" );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
189 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
190 else if (name == "units")
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
191 {
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
192 ui->cb_units->setCurrentIndex ( ui->cb_units->findText(props(1*i +1).string_value ().c_str ()) );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
193 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
194 else if (name == "horizontalalignment")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
195 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
196 ui->cb_horz_align->setCurrentIndex ( ui->cb_horz_align->findText(props(1*i +1).string_value ().c_str ()) );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
197 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
198 else if (name == "verticalalignment")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
199 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
200 ui->cb_vert_align->setCurrentIndex ( ui->cb_vert_align->findText(props(1*i +1).string_value ().c_str ()) );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
201 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
202 else if (name == "fontname")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
203 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
204 ui->cb_vert_align->setCurrentIndex ( ui->cb_font_name->findText(props(1*i +1).string_value ().c_str ()) );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
205 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
206 else if (name == "fontsize")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
207 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
208 ui->sb_font_size->setValue ( props(1*i +1).float_value () );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
209 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
210 else if (name == "fontweight")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
211 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
212 ui->cb_font_bold->setChecked ( props(1*i +1).string_value () == "bold" );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
213 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
214 else if (name == "fontangle")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
215 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
216 ui->cb_font_italic->setChecked ( props(1*i +1).string_value () == "italic" );
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
217 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
218 else if (name == "color")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
219 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
220 QColor color;
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
221 if (props(1*i +1).is_matrix_type ())
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
222 color = Utils::fromRgb (props(2*i +1).matrix_value ());
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
223 else
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
224 color.setNamedColor (props(2*i +1).string_value ().c_str ());
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
225
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
226 if (color.isValid ())
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
227 ui->btn_color->setPalette (QPalette (color));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
228 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
229
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
230 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
231
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
232 edit_string_changed (ui->edit_string->text ());
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
233 }
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
234
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
235 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
236 annotation_dialog::edit_string_changed (const QString &str)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
237 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
238 ui->button_box->button (QDialogButtonBox::Ok)->setEnabled (str.length () > 0);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
239 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
240
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
241 void
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
242 annotation_dialog::prompt_for_color ()
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
243 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
244 QWidget *widg = dynamic_cast<QWidget*> (sender ());
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
245 if (widg)
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
246 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
247 QColor color = widg->palette ().color (QPalette::Button);
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
248
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
249 color = QColorDialog::getColor(color, this);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
250
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
251 if (color.isValid ())
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
252 {
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
253 widg->setPalette (QPalette (color));
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
254
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
255 QString css = QString ("background-color: %1; border: 1px solid %2;")
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
256 .arg (color.name ())
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
257 .arg ("#000000");
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20144
diff changeset
258
20130
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
259 widg->setStyleSheet (css);
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
260 widg->update ();
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
261 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
262 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
263 }
c164cfc24bdd QtHandles: add annotations dialog
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
264