📄 qwt__legend__item_8cpp-source.html
字号:
<!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_legend_item.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.6 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li id="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul></div><h1>qwt_legend_item.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span><a name="l00002"></a>00002 <span class="comment"> * Qwt Widget Library</span><a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 1997 Josef Wilgen</span><a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 Uwe Rathmann</span><a name="l00005"></a>00005 <span class="comment"> * </span><a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span><a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span><a name="l00008"></a>00008 <span class="comment"> *****************************************************************************/</span><a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="comment">// vim: expandtab</span><a name="l00011"></a>00011 <a name="l00012"></a>00012 <span class="preprocessor">#include <qpainter.h></span><a name="l00013"></a>00013 <span class="preprocessor">#include <qdrawutil.h></span><a name="l00014"></a>00014 <span class="preprocessor">#include <qstyle.h></span><a name="l00015"></a>00015 <span class="preprocessor">#include <qpen.h></span><a name="l00016"></a>00016 <span class="preprocessor">#if QT_VERSION >= 0x040000</span><a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#include <qevent.h></span><a name="l00018"></a>00018 <span class="preprocessor">#include <qstyleoption.h></span><a name="l00019"></a>00019 <span class="preprocessor">#endif</span><a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#include "qwt_math.h"</span><a name="l00021"></a>00021 <span class="preprocessor">#include "qwt_painter.h"</span><a name="l00022"></a>00022 <span class="preprocessor">#include "qwt_symbol.h"</span><a name="l00023"></a>00023 <span class="preprocessor">#include "qwt_legend_item.h"</span><a name="l00024"></a>00024 <a name="l00025"></a>00025 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> ButtonFrame = 2;<a name="l00026"></a>00026 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Margin = 2;<a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="keyword">static</span> QSize buttonShift(<span class="keyword">const</span> <a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a> *w)<a name="l00029"></a>00029 {<a name="l00030"></a>00030 <span class="preprocessor">#if QT_VERSION < 0x040000</span><a name="l00031"></a>00031 <span class="preprocessor"></span> <span class="keyword">const</span> <span class="keywordtype">int</span> ph = w->style().pixelMetric(<a name="l00032"></a>00032 QStyle::PM_ButtonShiftHorizontal, w);<a name="l00033"></a>00033 <span class="keyword">const</span> <span class="keywordtype">int</span> pv = w->style().pixelMetric(<a name="l00034"></a>00034 QStyle::PM_ButtonShiftVertical, w);<a name="l00035"></a>00035 <span class="preprocessor">#else</span><a name="l00036"></a>00036 <span class="preprocessor"></span> QStyleOption option;<a name="l00037"></a>00037 option.<a class="code" href="class_qwt_legend_item.html#38a315635d2b08b57af0d58e2136ed70">init</a>(w);<a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="keyword">const</span> <span class="keywordtype">int</span> ph = w->style()->pixelMetric(<a name="l00040"></a>00040 QStyle::PM_ButtonShiftHorizontal, &option, w);<a name="l00041"></a>00041 <span class="keyword">const</span> <span class="keywordtype">int</span> pv = w->style()->pixelMetric(<a name="l00042"></a>00042 QStyle::PM_ButtonShiftVertical, &option, w);<a name="l00043"></a>00043 <span class="preprocessor">#endif</span><a name="l00044"></a>00044 <span class="preprocessor"></span> <span class="keywordflow">return</span> QSize(ph, pv);<a name="l00045"></a>00045 }<a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keyword">class </span>QwtLegendItem::PrivateData<a name="l00048"></a>00048 {<a name="l00049"></a>00049 <span class="keyword">public</span>:<a name="l00050"></a>00050 PrivateData():<a name="l00051"></a>00051 <a class="code" href="class_qwt_legend_item.html#2574e634e54eb7afff34ca24752c3f9b">itemMode</a>(<a class="code" href="class_qwt_legend.html">QwtLegend</a>::ReadOnlyItem),<a name="l00052"></a>00052 <a class="code" href="class_qwt_legend_item.html#d88e70289e552d67f881d0435fae1098">isDown</a>(false),<a name="l00053"></a>00053 <a class="code" href="class_qwt_legend_item.html#3326305e42b8904e55bf0c358b69267a">identifierWidth</a>(8),<a name="l00054"></a>00054 <a class="code" href="class_qwt_legend_item.html#53cd8956bab00b09be587da0bb7ca42b">identifierMode</a>(<a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a>::ShowLine | <a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a>::ShowText),<a name="l00055"></a>00055 <a class="code" href="class_qwt_legend_item.html#3ca8da18f186d02388b99d9de79f40b5">curvePen</a>(Qt::NoPen),<a name="l00056"></a>00056 <a class="code" href="class_qwt_legend_item.html#dc59d1683f3bb11a795098776e76c0bc">spacing</a>(Margin)<a name="l00057"></a>00057 {<a name="l00058"></a>00058 }<a name="l00059"></a>00059 <a name="l00060"></a>00060 <a class="code" href="class_qwt_legend.html#b216dd2dba9ebf6cb0ed2dd621a652e0">QwtLegend::LegendItemMode</a> <a class="code" href="class_qwt_legend_item.html#2574e634e54eb7afff34ca24752c3f9b">itemMode</a>;<a name="l00061"></a>00061 <span class="keywordtype">bool</span> <a class="code" href="class_qwt_legend_item.html#d88e70289e552d67f881d0435fae1098">isDown</a>;<a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend_item.html#3326305e42b8904e55bf0c358b69267a">identifierWidth</a>;<a name="l00064"></a>00064 <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend_item.html#53cd8956bab00b09be587da0bb7ca42b">identifierMode</a>;<a name="l00065"></a>00065 <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> <a class="code" href="class_qwt_legend_item.html#18ea9b789197ce0d6eedae02d27f5a55">symbol</a>;<a name="l00066"></a>00066 QPen <a class="code" href="class_qwt_legend_item.html#3ca8da18f186d02388b99d9de79f40b5">curvePen</a>;<a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend_item.html#dc59d1683f3bb11a795098776e76c0bc">spacing</a>;<a name="l00069"></a>00069 };<a name="l00070"></a>00070 <a name="l00074"></a><a class="code" href="class_qwt_legend_item.html#46f61a0eaaf24a3a78d498db3fc8c457">00074</a> <a class="code" href="class_qwt_legend_item.html#46f61a0eaaf24a3a78d498db3fc8c457">QwtLegendItem::QwtLegendItem</a>(QWidget *parent):<a name="l00075"></a>00075 <a class="code" href="class_qwt_text_label.html">QwtTextLabel</a>(parent)<a name="l00076"></a>00076 {<a name="l00077"></a>00077 d_data = <span class="keyword">new</span> PrivateData;<a name="l00078"></a>00078 init(<a class="code" href="class_qwt_text.html">QwtText</a>());<a name="l00079"></a>00079 }<a name="l00080"></a>00080 <a name="l00087"></a><a class="code" href="class_qwt_legend_item.html#e806668ed7ddd57ea4ce88fc6ea960aa">00087</a> <a class="code" href="class_qwt_legend_item.html#46f61a0eaaf24a3a78d498db3fc8c457">QwtLegendItem::QwtLegendItem</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &symbol, <a name="l00088"></a>00088 <span class="keyword">const</span> QPen &curvePen, <span class="keyword">const</span> <a class="code" href="class_qwt_text.html">QwtText</a> &text, <a name="l00089"></a>00089 QWidget *parent):<a name="l00090"></a>00090 <a class="code" href="class_qwt_text_label.html">QwtTextLabel</a>(parent)<a name="l00091"></a>00091 {<a name="l00092"></a>00092 d_data = <span class="keyword">new</span> PrivateData;<a name="l00093"></a>00093 <a name="l00094"></a>00094 d_data->symbol = <a class="code" href="class_qwt_legend_item.html#18ea9b789197ce0d6eedae02d27f5a55">symbol</a>;<a name="l00095"></a>00095 d_data->curvePen = curvePen;<a name="l00096"></a>00096 <a name="l00097"></a>00097 init(<a class="code" href="class_qwt_text_label.html#6ff4f9a87e11594740f312c8522f933e">text</a>);<a name="l00098"></a>00098 }<a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="keywordtype">void</span> QwtLegendItem::init(<span class="keyword">const</span> <a class="code" href="class_qwt_text.html">QwtText</a> &text)<a name="l00101"></a>00101 {<a name="l00102"></a>00102 <a class="code" href="class_qwt_text_label.html#833d27574b72bbc135f2972c72382eba">setMargin</a>(Margin);<a name="l00103"></a>00103 <a class="code" href="class_qwt_text_label.html#ad25ab34c219f8d97ec7c39d064ed4a0">setIndent</a>(<a class="code" href="class_qwt_text_label.html#b754bebe50bc0e713cde9ba58bf6c3c8">margin</a>() + d_data->identifierWidth + 2 * d_data->spacing);<a name="l00104"></a>00104 <a class="code" href="class_qwt_legend_item.html#8420c4d8cd73945a25697109df5c2f0e">setText</a>(<a class="code" href="class_qwt_text_label.html#6ff4f9a87e11594740f312c8522f933e">text</a>);<a name="l00105"></a>00105 }<a name="l00106"></a>00106 <a name="l00108"></a><a class="code" href="class_qwt_legend_item.html#8c98d47b26d4ad3af98bffc7107f6fc9">00108</a> <a class="code" href="class_qwt_legend_item.html#8c98d47b26d4ad3af98bffc7107f6fc9">QwtLegendItem::~QwtLegendItem</a>()<a name="l00109"></a>00109 {<a name="l00110"></a>00110 <span class="keyword">delete</span> d_data;<a name="l00111"></a>00111 d_data = NULL;<a name="l00112"></a>00112 }<a name="l00113"></a>00113 <a name="l00120"></a><a class="code" href="class_qwt_legend_item.html#8420c4d8cd73945a25697109df5c2f0e">00120</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#8420c4d8cd73945a25697109df5c2f0e">QwtLegendItem::setText</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_text.html">QwtText</a> &text)<a name="l00121"></a>00121 {<a name="l00122"></a>00122 <span class="keyword">const</span> <span class="keywordtype">int</span> flags = Qt::AlignLeft | Qt::AlignVCenter<a name="l00123"></a>00123 <span class="preprocessor">#if QT_VERSION < 0x040000</span><a name="l00124"></a>00124 <span class="preprocessor"></span> | Qt::WordBreak | Qt::ExpandTabs;<a name="l00125"></a>00125 <span class="preprocessor">#else</span><a name="l00126"></a>00126 <span class="preprocessor"></span> | Qt::TextExpandTabs | Qt::TextWordWrap;<a name="l00127"></a>00127 <span class="preprocessor">#endif</span><a name="l00128"></a>00128 <span class="preprocessor"></span><a name="l00129"></a>00129 <a class="code" href="class_qwt_text.html">QwtText</a> txt = <a class="code" href="class_qwt_text_label.html#6ff4f9a87e11594740f312c8522f933e">text</a>;<a name="l00130"></a>00130 txt.<a class="code" href="class_qwt_text.html#2e71d427de766455323794f27d369a5d">setRenderFlags</a>(flags);<a name="l00131"></a>00131 <a name="l00132"></a>00132 <a class="code" href="class_qwt_text_label.html#b300b9a0a6392e180f2caff41ba2b9b8">QwtTextLabel::setText</a>(txt);<a name="l00133"></a>00133 }<a name="l00134"></a>00134 <a name="l00142"></a><a class="code" href="class_qwt_legend_item.html#e6487dbe8f2c72512887df8bcb648d53">00142</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#e6487dbe8f2c72512887df8bcb648d53">QwtLegendItem::setItemMode</a>(<a class="code" href="class_qwt_legend.html#b216dd2dba9ebf6cb0ed2dd621a652e0">QwtLegend::LegendItemMode</a> mode) <a name="l00143"></a>00143 { <a name="l00144"></a>00144 d_data->itemMode = mode; <a name="l00145"></a>00145 d_data->isDown = <span class="keyword">false</span>; <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="preprocessor">#if QT_VERSION >= 0x040000</span><a name="l00148"></a>00148 <span class="preprocessor"></span> <span class="keyword">using namespace </span>Qt;<a name="l00149"></a>00149 <span class="preprocessor">#endif</span><a name="l00150"></a>00150 <span class="preprocessor"></span> setFocusPolicy(mode != QwtLegend::ReadOnlyItem ? TabFocus : NoFocus);<a name="l00151"></a>00151 <a class="code" href="class_qwt_text_label.html#833d27574b72bbc135f2972c72382eba">setMargin</a>(ButtonFrame + Margin);<a name="l00152"></a>00152 <a name="l00153"></a>00153 updateGeometry();<a name="l00154"></a>00154 }<a name="l00155"></a>00155 <a name="l00161"></a><a class="code" href="class_qwt_legend_item.html#2574e634e54eb7afff34ca24752c3f9b">00161</a> <a class="code" href="class_qwt_legend.html#b216dd2dba9ebf6cb0ed2dd621a652e0">QwtLegend::LegendItemMode</a> <a class="code" href="class_qwt_legend_item.html#2574e634e54eb7afff34ca24752c3f9b">QwtLegendItem::itemMode</a>()<span class="keyword"> const </span><a name="l00162"></a>00162 <span class="keyword"></span>{ <a name="l00163"></a>00163 <span class="keywordflow">return</span> d_data->itemMode; <a name="l00164"></a>00164 }<a name="l00165"></a>00165 <a name="l00173"></a><a class="code" href="class_qwt_legend_item.html#cbd7bb723c868b26bc91cfbc54ade719">00173</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#cbd7bb723c868b26bc91cfbc54ade719">QwtLegendItem::setIdentifierMode</a>(<span class="keywordtype">int</span> mode)<a name="l00174"></a>00174 {<a name="l00175"></a>00175 <span class="keywordflow">if</span> ( mode != d_data->identifierMode )<a name="l00176"></a>00176 {<a name="l00177"></a>00177 d_data->identifierMode = mode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -