comparison widgets/TransformFinder.cpp @ 423:5a55d0683ee5

* More twiddling with TransformFinder
author Chris Cannam
date Mon, 29 Sep 2008 11:11:42 +0000
parents ea9e41027b93
children 374b72f5b4bb
comparison
equal deleted inserted replaced
422:ea9e41027b93 423:5a55d0683ee5
23 #include <QLabel> 23 #include <QLabel>
24 //#include <SelectableLabel> 24 //#include <SelectableLabel>
25 #include <QDialogButtonBox> 25 #include <QDialogButtonBox>
26 #include <QScrollArea> 26 #include <QScrollArea>
27 #include <QApplication> 27 #include <QApplication>
28 28 #include <QDesktopWidget>
29 SelectableLabel::SelectableLabel(QWidget *parent) : 29
30 QLabel(parent), 30 SelectableLabel::SelectableLabel(QWidget *p) :
31 QLabel(p),
31 m_selected(false) 32 m_selected(false)
32 { 33 {
33 setStyleSheet("QLabel:hover { background: #e0e0e0; text: black; } QLabel:!hover { background: white; text: black } QLabel { padding: 4px }");
34
35 setTextFormat(Qt::RichText); 34 setTextFormat(Qt::RichText);
36 setLineWidth(2); 35 // setLineWidth(2);
37 setFixedWidth(420); 36 // setFixedWidth(480);
37 setupStyle();
38 } 38 }
39 39
40 void 40 void
41 SelectableLabel::setUnselectedText(QString text) 41 SelectableLabel::setUnselectedText(QString text)
42 { 42 {
56 resize(sizeHint()); 56 resize(sizeHint());
57 } 57 }
58 } 58 }
59 59
60 void 60 void
61 SelectableLabel::setupStyle()
62 {
63 if (m_selected) {
64 setWordWrap(true);
65 setStyleSheet("QLabel:hover { background: #e0e0e0; color: black; } QLabel:!hover { background: #f0f0f0; color: black } QLabel { padding: 7px }");
66
67 // setFrameStyle(QFrame::Box | QFrame::Plain);
68 } else {
69 setWordWrap(false);
70 setStyleSheet("QLabel:hover { background: #e0e0e0; color: black; } QLabel:!hover { background: white; color: black } QLabel { padding: 7px }");
71
72 // setFrameStyle(QFrame::NoFrame);
73 }
74 }
75
76 void
61 SelectableLabel::setSelected(bool s) 77 SelectableLabel::setSelected(bool s)
62 { 78 {
63 if (m_selected == s) return; 79 if (m_selected == s) return;
64 m_selected = s; 80 m_selected = s;
65 if (m_selected) { 81 if (m_selected) {
66 setText(m_selectedText); 82 setText(m_selectedText);
67 setWordWrap(true);
68 // setFrameStyle(QFrame::Box | QFrame::Plain);
69 } else { 83 } else {
70 setText(m_unselectedText); 84 setText(m_unselectedText);
71 setWordWrap(false); 85 }
72 // setFrameStyle(QFrame::NoFrame); 86 setupStyle();
73 }
74 // resize(sizeHint());
75 parentWidget()->resize(parentWidget()->sizeHint()); 87 parentWidget()->resize(parentWidget()->sizeHint());
76 } 88 }
77 89
78 void 90 void
79 SelectableLabel::toggle() 91 SelectableLabel::toggle()
82 } 94 }
83 95
84 void 96 void
85 SelectableLabel::mousePressEvent(QMouseEvent *e) 97 SelectableLabel::mousePressEvent(QMouseEvent *e)
86 { 98 {
87 toggle(); 99 setSelected(true);
88 emit selectionChanged(); 100 emit selectionChanged();
89 } 101 }
90 102
91 void 103 void
92 SelectableLabel::mouseDoubleClickEvent(QMouseEvent *e) 104 SelectableLabel::mouseDoubleClickEvent(QMouseEvent *e)
149 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); 161 palette.setColor(QPalette::Window, palette.color(QPalette::Base));
150 m_resultsFrame->setPalette(palette); 162 m_resultsFrame->setPalette(palette);
151 m_resultsScroll->setPalette(palette); 163 m_resultsScroll->setPalette(palette);
152 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box); 164 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box);
153 m_resultsLayout = new QVBoxLayout; 165 m_resultsLayout = new QVBoxLayout;
166 m_resultsLayout->setSpacing(0);
167 m_resultsLayout->setContentsMargins(0, 0, 0, 0);
154 m_resultsFrame->setLayout(m_resultsLayout); 168 m_resultsFrame->setLayout(m_resultsLayout);
155 m_resultsScroll->setWidget(m_resultsFrame); 169 m_resultsScroll->setWidget(m_resultsFrame);
156 m_resultsFrame->show(); 170 m_resultsFrame->show();
157 } 171 }
158 172
159 resize(500, 400); //!!! 173 QDesktopWidget *desktop = QApplication::desktop();
160 m_resultsFrame->resize(480, 380); 174 QRect available = desktop->availableGeometry();
175
176 int width = available.width() / 2;
177 int height = available.height() / 2;
178 if (height < 450) {
179 if (available.height() > 500) height = 450;
180 }
181 if (width < 600) {
182 if (available.width() > 650) width = 600;
183 }
184
185 resize(width, height);
186 raise();
161 } 187 }
162 188
163 TransformFinder::~TransformFinder() 189 TransformFinder::~TransformFinder()
164 { 190 {
165 } 191 }
248 label->setPalette(palette); 274 label->setPalette(palette);
249 m_labels.push_back(label); 275 m_labels.push_back(label);
250 } 276 }
251 277
252 m_labels[i]->setObjectName(desc.identifier); 278 m_labels[i]->setObjectName(desc.identifier);
253 m_selectedTransform = desc.identifier; 279 m_labels[i]->setFixedWidth(this->width() - 40);
254 m_labels[i]->setUnselectedText(labelText); 280 m_labels[i]->setUnselectedText(labelText);
255 m_labels[i]->setSelectedText(selectedText); 281 m_labels[i]->setSelectedText(selectedText);
282
283 /*
284 m_labels[i]->setSelected(false);
285 m_selectedTransform = "";
286 */
287
256 m_labels[i]->setSelected(i == 0); 288 m_labels[i]->setSelected(i == 0);
289 if (i == 0) {
290 m_selectedTransform = desc.identifier;
291 }
257 292
258 /* 293 /*
259 QSize sh = m_labels[i]->sizeHint(); 294 QSize sh = m_labels[i]->sizeHint();
260 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl; 295 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl;
261 height += sh.height(); 296 height += sh.height();