1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Qwt User's Guide: qwt_arrbtn.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>qwt_arrbtn.cpp</h1><pre class="fragment"><div>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span>
00002 <span class="comment"> * Qwt Widget Library</span>
00003 <span class="comment"> * Copyright (C) 1997 Josef Wilgen</span>
00004 <span class="comment"> * Copyright (C) 2002 Uwe Rathmann</span>
00005 <span class="comment"> * </span>
00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span>
00008 <span class="comment"> *****************************************************************************/</span>
00009
00010 <span class="preprocessor">#include <qpainter.h></span>
00011 <span class="preprocessor">#include <qstyle.h></span>
00012 <span class="preprocessor">#include <qevent.h></span>
00013 <span class="preprocessor">#include "<a class="code" href="qwt__math_8h.html">qwt_math.h</a>"</span>
00014 <span class="preprocessor">#include "qwt_arrbtn.h"</span>
00015
00016 <span class="preprocessor">#if 1</span>
00017 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> MaxNum = 3;
00018 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Margin = 2;
00019 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Spacing = 1;
00020 <span class="preprocessor">#endif</span>
00021 <span class="preprocessor"></span>
<a name="l00028"></a><a class="code" href="class_qwt_arrow_button.html#a0">00028</a> <a class="code" href="class_qwt_arrow_button.html#a0">QwtArrowButton::QwtArrowButton</a>(<span class="keywordtype">int</span> num, Qt::ArrowType arrowType,
00029 QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name):
00030 QPushButton (parent, name),
00031 d_num(<a class="code" href="qwt__math_8h.html#a37">qwtLim</a>(num,1,MaxNum)),
00032 d_arrowType(arrowType)
00033 {
00034 <span class="comment">// We don't need a pixmap, but setting one toggles</span>
00035 <span class="comment">// QPushButton in pixmap mode what removes text</span>
00036 <span class="comment">// related properties from thy style engines.</span>
00037
00038 setPixmap(QPixmap());
00039 setAutoRepeat(TRUE);
00040 setAutoDefault(FALSE);
00041 }
00042
<a name="l00046"></a><a class="code" href="class_qwt_arrow_button.html#a1">00046</a> Qt::ArrowType <a class="code" href="class_qwt_arrow_button.html#a1">QwtArrowButton::arrowType</a>()<span class="keyword"> const </span>
00047 <span class="keyword"></span>{
00048 <span class="keywordflow">return</span> d_arrowType;
00049 }
00050
<a name="l00054"></a><a class="code" href="class_qwt_arrow_button.html#a2">00054</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_arrow_button.html#a2">QwtArrowButton::num</a>()<span class="keyword"> const </span>
00055 <span class="keyword"></span>{
00056 <span class="keywordflow">return</span> d_num;
00057 }
00058
<a name="l00062"></a><a class="code" href="class_qwt_arrow_button.html#b2">00062</a> QRect <a class="code" href="class_qwt_arrow_button.html#b2">QwtArrowButton::labelRect</a>()<span class="keyword"> const</span>
00063 <span class="keyword"></span>{
00064 QRect r =
00065 <span class="preprocessor">#if QT_VERSION < 300</span>
00066 <span class="preprocessor"></span> style().buttonRect(rect().x(), rect().y(),
00067 rect().width(), rect().height());
00068 <span class="preprocessor">#else</span>
00069 <span class="preprocessor"></span> style().subRect(QStyle::SR_PushButtonContents, <span class="keyword">this</span>);
00070 <span class="preprocessor">#endif</span>
00071 <span class="preprocessor"></span>
00072 r.setRect(r.x() + Margin, r.y() + Margin,
00073 r.width() - 2 * Margin, r.height() - 2 * Margin);
00074
00075 <span class="keywordflow">if</span> ( isDown() )
00076 {
00077 <span class="keywordtype">int</span> ph, pv;
00078 <span class="preprocessor">#if QT_VERSION < 300</span>
00079 <span class="preprocessor"></span> style().getButtonShift(ph, pv);
00080 <span class="preprocessor">#else</span>
00081 <span class="preprocessor"></span> ph = style().pixelMetric(
00082 QStyle::PM_ButtonShiftHorizontal, <span class="keyword">this</span>);
00083 pv = style().pixelMetric(
00084 QStyle::PM_ButtonShiftVertical, <span class="keyword">this</span>);
00085 <span class="preprocessor">#endif</span>
00086 <span class="preprocessor"></span> r.moveBy(ph, pv);
00087 }
00088
00089 <span class="keywordflow">return</span> r;
00090 }
00091
<a name="l00096"></a><a class="code" href="class_qwt_arrow_button.html#b0">00096</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_arrow_button.html#b0">QwtArrowButton::drawButtonLabel</a>(QPainter *p)
00097 {
00098 <span class="keyword">const</span> QRect r = <a class="code" href="class_qwt_arrow_button.html#b2">labelRect</a>();
00099
00100 QSize boundingSize = <a class="code" href="class_qwt_arrow_button.html#b2">labelRect</a>().size();
00101 <span class="keywordflow">if</span> ( d_arrowType == Qt::UpArrow || d_arrowType == Qt::DownArrow )
00102 boundingSize.transpose();
00103
00104 <span class="keyword">const</span> <span class="keywordtype">int</span> w = (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum;
00105
00106 QSize arrow = <a class="code" href="class_qwt_arrow_button.html#b3">arrowSize</a>(Qt::RightArrow,
00107 QSize(w, boundingSize.height()));
00108
00109 <span class="keywordflow">if</span> ( d_arrowType == Qt::UpArrow || d_arrowType == Qt::DownArrow )
00110 arrow.transpose();
00111
00112 QRect contentsSize; <span class="comment">// aligned rect where to paint all arrows</span>
00113 <span class="keywordflow">if</span> ( d_arrowType == Qt::LeftArrow || d_arrowType == Qt::RightArrow )
00114 {
00115 contentsSize.setWidth(d_num * arrow.width()
00116 + (d_num - 1) * Spacing);
00117 contentsSize.setHeight(arrow.height());
00118 }
00119 <span class="keywordflow">else</span>
00120 {
00121 contentsSize.setWidth(arrow.width());
00122 contentsSize.setHeight(d_num * arrow.height()
00123 + (d_num - 1) * Spacing);
00124 }
00125
00126 QRect arrowRect(contentsSize);
00127 arrowRect.moveCenter(r.center());
00128 arrowRect.setSize(arrow);
00129
00130 p->save();
00131 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < d_num; i++)
00132 {
00133 <a class="code" href="class_qwt_arrow_button.html#b1">drawArrow</a>(p, arrowRect, d_arrowType);
00134
00135 <span class="keywordflow">if</span> ( d_arrowType == Qt::LeftArrow || d_arrowType == Qt::RightArrow )
00136 arrowRect.moveBy(arrow.width() + Spacing, 0);
00137 <span class="keywordflow">else</span>
00138 arrowRect.moveBy(0, arrow.height() + Spacing);
00139 }
00140 p->restore();
00141
00142 <span class="preprocessor">#if QT_VERSION >= 300</span>
00143 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( hasFocus() )
00144 {
00145 <span class="keyword">const</span> QRect focusRect =
00146 style().subRect(QStyle::SR_PushButtonFocusRect, <span class="keyword">this</span>);
00147 style().drawPrimitive(QStyle::PE_FocusRect, p,
00148 focusRect, colorGroup());
00149 }
00150 <span class="preprocessor">#endif</span>
00151 <span class="preprocessor"></span>}
00152
<a name="l00160"></a><a class="code" href="class_qwt_arrow_button.html#b1">00160</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_arrow_button.html#b1">QwtArrowButton::drawArrow</a>(QPainter *p,
00161 <span class="keyword">const</span> QRect &r, Qt::ArrowType arrowType)<span class="keyword"> const </span>
00162 <span class="keyword"></span>{
00163 QPointArray pa(3);
00164
00165 <span class="keywordflow">switch</span>(arrowType)
00166 {
00167 <span class="keywordflow">case</span> Qt::UpArrow:
00168 pa.setPoint(0, r.bottomLeft());
00169 pa.setPoint(1, r.bottomRight());
00170 pa.setPoint(2, r.center().x(), r.top());
00171 <span class="keywordflow">break</span>;
00172 <span class="keywordflow">case</span> Qt::DownArrow:
00173 pa.setPoint(0, r.topLeft());
00174 pa.setPoint(1, r.topRight());
00175 pa.setPoint(2, r.center().x(), r.bottom());
00176 <span class="keywordflow">break</span>;
00177 <span class="keywordflow">case</span> Qt::RightArrow:
00178 pa.setPoint(0, r.topLeft());
00179 pa.setPoint(1, r.bottomLeft());
00180 pa.setPoint(2, r.right(), r.center().y());
00181 <span class="keywordflow">break</span>;
00182 <span class="keywordflow">case</span> Qt::LeftArrow:
00183 pa.setPoint(0, r.topRight());
00184 pa.setPoint(1, r.bottomRight());
00185 pa.setPoint(2, r.left(), r.center().y());
00186 <span class="keywordflow">break</span>;
00187 }
00188
00189 p->setPen(colorGroup().buttonText());
00190 p->setBrush(colorGroup().brush(QColorGroup::ButtonText));
00191 p->drawPolygon(pa);
00192 }
00193
00194
<a name="l00198"></a><a class="code" href="class_qwt_arrow_button.html#a5">00198</a> QSizePolicy <a class="code" href="class_qwt_arrow_button.html#a5">QwtArrowButton::sizePolicy</a>()<span class="keyword"> const</span>
00199 <span class="keyword"></span>{
00200 QSizePolicy policy;
00201 <span class="keywordflow">if</span> ( d_arrowType == Qt::LeftArrow || d_arrowType == Qt::RightArrow )
00202 policy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
00203 <span class="keywordflow">else</span>
00204 policy = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
00205
00206 <span class="keywordflow">return</span> policy;
00207 }
00208
<a name="l00212"></a><a class="code" href="class_qwt_arrow_button.html#a3">00212</a> QSize <a class="code" href="class_qwt_arrow_button.html#a3">QwtArrowButton::sizeHint</a>()<span class="keyword"> const</span>
00213 <span class="keyword"></span>{
00214 <span class="keywordflow">return</span> <a class="code" href="class_qwt_arrow_button.html#a4">minimumSizeHint</a>();
00215 }
00216
<a name="l00220"></a><a class="code" href="class_qwt_arrow_button.html#a4">00220</a> QSize <a class="code" href="class_qwt_arrow_button.html#a4">QwtArrowButton::minimumSizeHint</a>()<span class="keyword"> const</span>
00221 <span class="keyword"></span>{
00222 <span class="keyword">const</span> QSize asz = <a class="code" href="class_qwt_arrow_button.html#b3">arrowSize</a>(Qt::RightArrow, QSize());
00223
00224 QSize sz(
00225 2 * Margin + (MaxNum - 1) * Spacing + MaxNum * asz.width(),
00226 2 * Margin + asz.height()
00227 );
00228
00229 <span class="keywordflow">if</span> ( d_arrowType == Qt::UpArrow || d_arrowType == Qt::DownArrow )
00230 sz.transpose();
00231
00232 <span class="preprocessor">#if QT_VERSION < 300</span>
00233 <span class="preprocessor"></span> <span class="keywordtype">int</span> bm = style().buttonMargin() - 1;
00234 sz += QSize(2 * bm, 2 * bm);
00235 <span class="preprocessor">#else</span>
00236 <span class="preprocessor"></span> sz = style().sizeFromContents(QStyle::CT_PushButton, <span class="keyword">this</span>, sz);
00237 <span class="preprocessor">#endif</span>
00238 <span class="preprocessor"></span> <span class="keywordflow">return</span> sz;
00239 }
00240
<a name="l00248"></a><a class="code" href="class_qwt_arrow_button.html#b3">00248</a> QSize <a class="code" href="class_qwt_arrow_button.html#b3">QwtArrowButton::arrowSize</a>(Qt::ArrowType arrowType,
00249 <span class="keyword">const</span> QSize &boundingSize)<span class="keyword"> const</span>
00250 <span class="keyword"></span>{
00251 QSize bs = boundingSize;
00252 <span class="keywordflow">if</span> ( arrowType == Qt::UpArrow || arrowType == Qt::DownArrow )
00253 bs.transpose();
00254
00255 <span class="keyword">const</span> <span class="keywordtype">int</span> MinLen = 2;
00256 <span class="keyword">const</span> QSize sz = bs.expandedTo(
00257 QSize(MinLen, 2 * MinLen - 1)); <span class="comment">// minimum</span>
00258
00259 <span class="keywordtype">int</span> w = sz.width();
00260 <span class="keywordtype">int</span> h = 2 * w - 1;
00261
00262 <span class="keywordflow">if</span> ( h > sz.height() )
00263 {
00264 h = sz.height();
00265 w = (h + 1) / 2;
00266 }
00267
00268 QSize arrSize(w, h);
00269 <span class="keywordflow">if</span> ( arrowType == Qt::UpArrow || arrowType == Qt::DownArrow )
00270 arrSize.transpose();
00271
00272 <span class="keywordflow">return</span> arrSize;
00273 }
00274
<a name="l00278"></a><a class="code" href="class_qwt_arrow_button.html#b4">00278</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_arrow_button.html#b4">QwtArrowButton::keyPressEvent</a>(QKeyEvent *e)
00279 {
00280 <span class="keywordflow">if</span> ( e->isAutoRepeat() && e->key() == Qt::Key_Space )
00281 emit clicked();
00282
00283 QPushButton::keyPressEvent(e);
00284 }
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>
|