comparison demos/browser/searchlineedit.d @ 77:0654fc9bac95

more porting
author mandel
date Sun, 24 May 2009 13:46:32 +0000
parents 37caa90ce503
children 85c59c4e5f19
comparison
equal deleted inserted replaced
76:454e4b4beb59 77:0654fc9bac95
71 setFocusPolicy(Qt.NoFocus); 71 setFocusPolicy(Qt.NoFocus);
72 } 72 }
73 73
74 void paintEvent(QPaintEvent event) 74 void paintEvent(QPaintEvent event)
75 { 75 {
76 //Q_UNUSED(event); 76 auto painter = new QPainter(this);
77 QPainter painter(this);
78 int height = this.height(); 77 int height = this.height();
79 78
80 painter.setRenderHint(QPainter.Antialiasing, true); 79 painter.setRenderHint(QPainter.Antialiasing, true);
81 QColor color = palette().color(QPalette.Mid); 80 QColor color = palette().color(QPalette.Mid);
82 painter.setBrush(isDown() ? palette().color(QPalette.Dark) : palette().color(QPalette.Mid)); 81 painter.setBrush(isDown() ? palette().color(QPalette.Dark) : palette().color(QPalette.Mid));
90 int border = offset * 2; 89 int border = offset * 2;
91 painter.drawLine(border, border, width() - border, height - border); 90 painter.drawLine(border, border, width() - border, height - border);
92 painter.drawLine(border, height - border, width() - border, border); 91 painter.drawLine(border, height - border, width() - border, border);
93 } 92 }
94 93
95 void textChanged(QString text) 94 void textChanged(string text)
96 { 95 {
97 setVisible(!text.isEmpty()); 96 setVisible(!text.isEmpty());
98 } 97 }
99 } 98 }
100 99
104 */ 103 */
105 class SearchButton : public QAbstractButton 104 class SearchButton : public QAbstractButton
106 { 105 {
107 public: 106 public:
108 107
109 SearchButton(QWidget parent = null) 108 this(QWidget parent = null)
110 { 109 {
111 super(parent); 110 super(parent);
112 m_menu = 0; 111 m_menu = 0;
113 setObjectName(QLatin1String("SearchButton")); 112 setObjectName(QLatin1String("SearchButton"));
114 setCursor(Qt.ArrowCursor); 113 setCursor(Qt.ArrowCursor);
115 setFocusPolicy(Qt.NoFocus); 114 setFocusPolicy(Qt.NoFocus);
116 } 115 }
117 116
118 void paintEvent(QPaintEvent event) 117 void paintEvent(QPaintEvent event)
119 { 118 {
120 //Q_UNUSED(event);
121 QPainterPath myPath; 119 QPainterPath myPath;
122 120
123 int radius = (height() / 5) * 2; 121 int radius = (height() / 5) * 2;
124 QRect circle(height() / 3 - 1, height() / 4, radius, radius); 122 QRect circle = QRect(height() / 3 - 1, height() / 4, radius, radius);
125 myPath.addEllipse(circle); 123 myPath.addEllipse(circle);
126 124
127 myPath.arcMoveTo(circle, 300); 125 myPath.arcMoveTo(circle, 300);
128 QPointF c = myPath.currentPosition(); 126 QPointF c = myPath.currentPosition();
129 int diff = height() / 7; 127 int diff = height() / 7;
130 myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff); 128 myPath.lineTo(qMin(width() - 2, cast(int) c.x() + diff), c.y() + diff);
131 129
132 QPainter painter(this); 130 auto painter = new QPainter(this);
133 painter.setRenderHint(QPainter.Antialiasing, true); 131 painter.setRenderHint(QPainter.Antialiasing, true);
134 painter.setPen(QPen(Qt.darkGray, 2)); 132 painter.setPen(QPen(Qt.darkGray, 2));
135 painter.drawPath(myPath); 133 painter.drawPath(myPath);
136 134
137 if (m_menu) { 135 if (m_menu) {
169 } 167 }
170 } 168 }
171 169
172 class SearchLineEdit : public ExLineEdit 170 class SearchLineEdit : public ExLineEdit
173 { 171 {
174 mixin Signal!("textChanged", QString /*text*/); 172 mixin Signal!("textChanged", string /*text*/);
175 173
176 public: 174 public:
177 175
178 /* 176 /*
179 SearchLineEdit is an enhanced QLineEdit 177 SearchLineEdit is an enhanced QLineEdit
191 189
192 QSizePolicy policy = sizePolicy(); 190 QSizePolicy policy = sizePolicy();
193 setSizePolicy(QSizePolicy.Preferred, policy.verticalPolicy()); 191 setSizePolicy(QSizePolicy.Preferred, policy.verticalPolicy());
194 } 192 }
195 193
196 QString inactiveText() 194 string inactiveText()
197 { 195 {
198 return m_inactiveText; 196 return m_inactiveText;
199 } 197 }
200 198
201 void setInactiveText(QString text) 199 void setInactiveText(string text)
202 { 200 {
203 m_inactiveText = text; 201 m_inactiveText = text;
204 } 202 }
205 203
206 QMenu menu() 204 QMenu menu()
207 { 205 {
208 if (!m_searchButton.m_menu) { 206 if (!m_searchButton.m_menu) {
209 m_searchButton.m_menu = new QMenu(m_searchButton); 207 m_searchButton.m_menu = new QMenu(m_searchButton);
210 if (isVisible()) 208 if (isVisible())
211 (const_cast<SearchLineEdit>(this)).updateGeometries(); 209 (cast(SearchLineEdit) this).updateGeometries();
212 } 210 }
213 return m_searchButton.m_menu; 211 return m_searchButton.m_menu;
214 } 212 }
215 213
216 void setMenu(QMenu menu) 214 void setMenu(QMenu menu)
236 QStyleOptionFrameV2 panel; 234 QStyleOptionFrameV2 panel;
237 initStyleOption(&panel); 235 initStyleOption(&panel);
238 QRect r = style().subElementRect(QStyle.SE_LineEditContents, &panel, this); 236 QRect r = style().subElementRect(QStyle.SE_LineEditContents, &panel, this);
239 QFontMetrics fm = fontMetrics(); 237 QFontMetrics fm = fontMetrics();
240 int horizontalMargin = lineEdit().x(); 238 int horizontalMargin = lineEdit().x();
241 QRect lineRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height()); 239 QRect lineRect = QRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height());
242 QPainter painter(this); 240 QPainter painter = new QPainter(this);
243 painter.setPen(palette().brush(QPalette.Disabled, QPalette.Text).color()); 241 painter.setPen(palette().brush(QPalette.Disabled, QPalette.Text).color());
244 painter.drawText(lineRect, Qt.AlignLeft|Qt.AlignVCenter, m_inactiveText); 242 painter.drawText(lineRect, Qt.AlignLeft|Qt.AlignVCenter, m_inactiveText);
245 } else { 243 } else {
246 ExLineEdit.paintEvent(event); 244 ExLineEdit.paintEvent(event);
247 } 245 }
257 menuWidth = (menuHeight / 5) * 4; 255 menuWidth = (menuHeight / 5) * 4;
258 m_searchButton.resize(QSize(menuWidth, menuHeight)); 256 m_searchButton.resize(QSize(menuWidth, menuHeight));
259 } 257 }
260 258
261 SearchButton m_searchButton; 259 SearchButton m_searchButton;
262 QString m_inactiveText; 260 string m_inactiveText;
263 } 261 }