Mercurial > hg > svgui
comparison widgets/TransformFinder.cpp @ 421:7466402a32c5
* moar pointless twiddlin
author | Chris Cannam |
---|---|
date | Fri, 26 Sep 2008 16:18:36 +0000 |
parents | f8e04ad8e7b1 |
children | ea9e41027b93 |
comparison
equal
deleted
inserted
replaced
420:f8e04ad8e7b1 | 421:7466402a32c5 |
---|---|
15 | 15 |
16 #include "TransformFinder.h" | 16 #include "TransformFinder.h" |
17 | 17 |
18 #include "transform/TransformFactory.h" | 18 #include "transform/TransformFactory.h" |
19 | 19 |
20 #include <QGridLayout> | 20 #include <QVBoxLayout> |
21 #include <QGridLayout> | 21 #include <QGridLayout> |
22 #include <QLineEdit> | 22 #include <QLineEdit> |
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 | 28 |
28 SelectableLabel::SelectableLabel(QWidget *parent) : | 29 SelectableLabel::SelectableLabel(QWidget *parent) : |
29 QLabel(parent), | 30 QLabel(parent), |
30 m_selected(false) | 31 m_selected(false) |
31 { | 32 { |
33 setStyleSheet("QLabel:hover { background: #e0e0e0; text: black; } QLabel:!hover { background: white; text: black } QLabel { padding: 4px }"); | |
34 | |
32 setTextFormat(Qt::RichText); | 35 setTextFormat(Qt::RichText); |
33 setLineWidth(2); | 36 setLineWidth(2); |
34 setFixedWidth(420); | 37 setFixedWidth(420); |
35 setWordWrap(true); | |
36 } | 38 } |
37 | 39 |
38 void | 40 void |
39 SelectableLabel::setUnselectedText(QString text) | 41 SelectableLabel::setUnselectedText(QString text) |
40 { | 42 { |
60 { | 62 { |
61 if (m_selected == s) return; | 63 if (m_selected == s) return; |
62 m_selected = s; | 64 m_selected = s; |
63 if (m_selected) { | 65 if (m_selected) { |
64 setText(m_selectedText); | 66 setText(m_selectedText); |
65 setFrameStyle(QFrame::Box | QFrame::Plain); | 67 setWordWrap(true); |
68 // setFrameStyle(QFrame::Box | QFrame::Plain); | |
66 } else { | 69 } else { |
67 setText(m_unselectedText); | 70 setText(m_unselectedText); |
68 setFrameStyle(QFrame::NoFrame); | 71 setWordWrap(false); |
69 } | 72 // setFrameStyle(QFrame::NoFrame); |
70 resize(sizeHint()); | 73 } |
74 // resize(sizeHint()); | |
71 parentWidget()->resize(parentWidget()->sizeHint()); | 75 parentWidget()->resize(parentWidget()->sizeHint()); |
72 } | 76 } |
73 | 77 |
74 void | 78 void |
75 SelectableLabel::toggle() | 79 SelectableLabel::toggle() |
80 void | 84 void |
81 SelectableLabel::mousePressEvent(QMouseEvent *e) | 85 SelectableLabel::mousePressEvent(QMouseEvent *e) |
82 { | 86 { |
83 toggle(); | 87 toggle(); |
84 emit selectionChanged(); | 88 emit selectionChanged(); |
89 } | |
90 | |
91 void | |
92 SelectableLabel::enterEvent(QEvent *) | |
93 { | |
94 // std::cerr << "enterEvent" << std::endl; | |
95 // QPalette palette = QApplication::palette(); | |
96 // palette.setColor(QPalette::Window, Qt::gray); | |
97 // setStyleSheet("background: gray"); | |
98 // setPalette(palette); | |
99 } | |
100 | |
101 void | |
102 SelectableLabel::leaveEvent(QEvent *) | |
103 { | |
104 // std::cerr << "leaveEvent" << std::endl; | |
105 // setStyleSheet("background: white"); | |
106 // QPalette palette = QApplication::palette(); | |
107 // palette.setColor(QPalette::Window, Qt::gray); | |
108 // setPalette(palette); | |
85 } | 109 } |
86 | 110 |
87 TransformFinder::TransformFinder(QWidget *parent) : | 111 TransformFinder::TransformFinder(QWidget *parent) : |
88 QDialog(parent), | 112 QDialog(parent), |
89 m_resultsFrame(0), | 113 m_resultsFrame(0), |
90 m_resultsLayout(0) | 114 m_resultsLayout(0) |
91 { | 115 { |
92 setWindowTitle(tr("Find a Transform")); | 116 setWindowTitle(tr("Find a Transform")); |
93 | 117 |
94 QGridLayout *mainGrid = new QGridLayout; | 118 QGridLayout *mainGrid = new QGridLayout; |
119 mainGrid->setVerticalSpacing(0); | |
95 setLayout(mainGrid); | 120 setLayout(mainGrid); |
96 | 121 |
97 mainGrid->addWidget(new QLabel(tr("Find:")), 0, 0); | 122 mainGrid->addWidget(new QLabel(tr("Find:")), 0, 0); |
98 | 123 |
99 QLineEdit *searchField = new QLineEdit; | 124 QLineEdit *searchField = new QLineEdit; |
109 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | 134 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | |
110 QDialogButtonBox::Cancel); | 135 QDialogButtonBox::Cancel); |
111 mainGrid->addWidget(bb, 2, 0, 1, 2); | 136 mainGrid->addWidget(bb, 2, 0, 1, 2); |
112 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | 137 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); |
113 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | 138 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); |
139 if (!m_resultsLayout) { | |
140 std::cerr << "creating frame & layout" << std::endl; | |
141 m_resultsFrame = new QWidget; | |
142 QPalette palette = m_resultsFrame->palette(); | |
143 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); | |
144 m_resultsFrame->setPalette(palette); | |
145 m_resultsScroll->setPalette(palette); | |
146 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box); | |
147 m_resultsLayout = new QVBoxLayout; | |
148 m_resultsFrame->setLayout(m_resultsLayout); | |
149 m_resultsScroll->setWidget(m_resultsFrame); | |
150 m_resultsFrame->show(); | |
151 } | |
114 | 152 |
115 resize(500, 400); //!!! | 153 resize(500, 400); //!!! |
154 m_resultsFrame->resize(480, 380); | |
116 } | 155 } |
117 | 156 |
118 TransformFinder::~TransformFinder() | 157 TransformFinder::~TransformFinder() |
119 { | 158 { |
120 } | 159 } |
149 } | 188 } |
150 std::cerr << "(" << j->score << ")" << std::endl; | 189 std::cerr << "(" << j->score << ")" << std::endl; |
151 } | 190 } |
152 */ | 191 */ |
153 | 192 |
154 if (!m_resultsLayout) { | |
155 std::cerr << "creating frame & layout" << std::endl; | |
156 m_resultsFrame = new QWidget; | |
157 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box); | |
158 m_resultsLayout = new QGridLayout; | |
159 m_resultsFrame->setLayout(m_resultsLayout); | |
160 m_resultsScroll->setWidget(m_resultsFrame); | |
161 m_resultsFrame->show(); | |
162 } | |
163 | |
164 i = 0; | 193 i = 0; |
165 int maxResults = 40; | 194 int maxResults = 40; |
166 int height = 0; | 195 int height = 0; |
167 int width = 0; | 196 int width = 0; |
168 | 197 |
203 selectedText += tr("<li>System identifier: %1</li>").arg(desc.identifier); | 232 selectedText += tr("<li>System identifier: %1</li>").arg(desc.identifier); |
204 selectedText += tr("</small></ul>"); | 233 selectedText += tr("</small></ul>"); |
205 | 234 |
206 if (i >= m_labels.size()) { | 235 if (i >= m_labels.size()) { |
207 SelectableLabel *label = new SelectableLabel(m_resultsFrame); | 236 SelectableLabel *label = new SelectableLabel(m_resultsFrame); |
208 m_resultsLayout->addWidget(label, i, 0); | 237 // m_resultsLayout->addWidget(label, i, 0); |
238 m_resultsLayout->addWidget(label); | |
209 connect(label, SIGNAL(selectionChanged()), this, | 239 connect(label, SIGNAL(selectionChanged()), this, |
210 SLOT(selectedLabelChanged())); | 240 SLOT(selectedLabelChanged())); |
241 QPalette palette = label->palette(); | |
242 label->setPalette(palette); | |
211 m_labels.push_back(label); | 243 m_labels.push_back(label); |
212 } | 244 } |
213 | 245 |
214 m_labels[i]->setObjectName(desc.identifier); | 246 m_labels[i]->setObjectName(desc.identifier); |
215 m_selectedTransform = desc.identifier; | 247 m_selectedTransform = desc.identifier; |
216 m_labels[i]->setUnselectedText(labelText); | 248 m_labels[i]->setUnselectedText(labelText); |
217 m_labels[i]->setSelectedText(selectedText); | 249 m_labels[i]->setSelectedText(selectedText); |
218 m_labels[i]->setSelected(i == 0); | 250 m_labels[i]->setSelected(i == 0); |