Tianchi  v0.0.2 build 20130701
C++ library for Qt with VC & mingW
tcguiutils.h
1 // **************************************************************************
2 // Tianchi C++ library for Qt (open source)
3 // 天池共享源码库
4 // 版权所有 (C) 天池共享源码库开发组
5 // 授权协议:请阅读天池共享源码库附带的授权协议
6 // **************************************************************************
7 // 文档说明:GUI相关常用单元
8 // ==========================================================================
9 // 开发日志:
10 // 日期 人员 说明
11 // --------------------------------------------------------------------------
12 // 2013.04.15 圣域天子 建立
13 //
14 // ==========================================================================
16 #ifndef TIANCHI_TCGUIUTILS_H
17 #define TIANCHI_TCGUIUTILS_H
18 
19 #include <tianchi/tcglobal.h>
20 
21 #include <QLabel>
22 #include <QCursor>
23 #include <QWidget>
24 #include <QToolBar>
25 #include <QToolButton>
26 #include <QTreeWidget>
27 #include <QDoubleSpinBox>
28 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
29 #include <QGuiApplication>
30 #else
31 #include <QApplication>
32 #endif
33 
39 class TIANCHI_API TcCursorCustom
40 {
41 protected:
42  TcCursorCustom(Qt::CursorShape shape)
43  {
44 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
45  QGuiApplication::setOverrideCursor(QCursor(shape));
46 #else
47  QApplication::setOverrideCursor(QCursor(shape));
48 #endif
49  }
50  virtual ~TcCursorCustom()
51  {
52  restore();
53  }
54  QWidget* m_parent;
55  QCursor m_cursor;
56 public:
58  inline void restore()
59  {
60 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
61  QGuiApplication::restoreOverrideCursor();
62 #else
63  QApplication::restoreOverrideCursor();
64 #endif
65  }
66 };
67 
82 class TIANCHI_API TcCursorWait : public TcCursorCustom
83 {
84 public:
85  TcCursorWait()
86  : TcCursorCustom(Qt::WaitCursor)
87  {
88  }
89 };
90 
106 class TIANCHI_API TcCursorBusy : public TcCursorCustom
107 {
108 public:
109  TcCursorBusy()
110  : TcCursorCustom(Qt::BusyCursor)
111  {
112  }
113 };
114 
115 namespace Tc
116 {
117 
118 // 在工具栏上创建一个按钮
119 TIANCHI_API QToolButton* createButton(QToolBar* toolBar,
120  QIcon icon, QString text, int width,
121  Qt::ToolButtonStyle style=Qt::ToolButtonTextBesideIcon);
122 
123 inline void setColumnBold(QTreeWidget* view)
124 {
125  for( int i=0;i<view->headerItem()->columnCount();i++ )
126  {
127  QFont font = view->headerItem()->font(i);
128  font.setBold(true);
129  view->headerItem()->setFont(i, font);
130  }
131 }
132 
133 inline void setColumnWidth(QTreeWidget* view, int column, int width, bool hide=false)
134 {
135  view->setColumnWidth(column, width);
136  view->setColumnHidden(column, hide);
137 }
138 
139 TIANCHI_API void createColumnMenu(QTreeWidget* view, QWidget* widget, const QString& ColumnSetupFunc);
140 
141 
142 TIANCHI_API void setColumnStyle(QTreeWidget* view, int fontSize=8, const QString &fontName="Tahoma");
143 
144 TIANCHI_API void cellStyle(QTreeWidgetItem* item, int startCol=-1, int endCol=-1,
145  bool bold=true, int alignment=Qt::AlignVCenter | Qt::AlignRight,
146  int cellHeight=25);
147 
148 
149 TIANCHI_API void cellFont(QTreeWidgetItem* item, int col, bool bold=false, int alignment=Qt::AlignVCenter | Qt::AlignLeft);
150 TIANCHI_API void cellColor(QTreeWidgetItem* item, int col, QColor color);
151 
152 TIANCHI_API void changeFont(QWidget* widget, const QString& fontName="Arial Narrow", int fontSize=8, bool bold=false);
153 TIANCHI_API void setFontTahoma(QWidget* widget, int fontSize=8, bool bold=false);
154 // 在 QTreeWidgetItem 上显示数值
155 TIANCHI_API void cellValue(QTreeWidgetItem* item, int column, const char* text, const QVariant& data=QVariant(), int size=0);
156 TIANCHI_API void cellValue(QTreeWidgetItem* item, int column, const QString& text, const QVariant& data=QVariant(), int size=0);
157 TIANCHI_API void cellValue(QTreeWidgetItem* item, int column, const QByteArray& text, const QVariant& data=QVariant(), int size=0);
158 TIANCHI_API void cellValue(QTreeWidgetItem* item, int column, double value);
159 TIANCHI_API void cellValue(QTreeWidgetItem* item, int column, double value, int digits);
160 TIANCHI_API void cellPrice(QTreeWidgetItem* item, int column, double value=0.0, int digits=0);
161 TIANCHI_API void cellPercent(QTreeWidgetItem* item, int column, double value=0.0, int digits=0);
162 
163 TIANCHI_API QLabel* createLabel(QTreeWidgetItem* item, int col, const QString& htmlText, const QVariant& data=QVariant());
164 
165 TIANCHI_API QDoubleSpinBox* createDoubleSpinBox(QTreeWidgetItem* item, int col,
166  int decimals, double min, double max, double step, double value);
167 TIANCHI_API double readDoubleSpinBoxValue(QTreeWidgetItem* item, int col);
168 
169 TIANCHI_API void CopyCell(QTreeWidget* view);
170 TIANCHI_API void CopyLine(QTreeWidget* view);
171 TIANCHI_API void CopyTable(QTreeWidget* view);
172 }
173 
174 #endif // TIANCHI_GUIUTILS_H