📄 style.cpp
字号:
#include "style.h"#include <qpainter.h>#include <qscrollbar.h>using namespace archos;AStyle *AStyle::get(){ if(s_instance == NULL) s_instance = new AStyle(Screen::mode()); else if (s_instance->m_mode != Screen::mode()) { delete s_instance; s_instance = new AStyle(Screen::mode()); } return s_instance;}AStyle::AStyle(ScreenMode mode) : QWindowsStyle() , m_mode(mode){ QString path = iconpath + Screen::prefix(); m_sgroovepix = path + "general/vslider_empty_area.png"; m_sgroovetoppix = path + "general/vslider_cursor_top.png"; m_sgroovebottompix = path + "general/vslider_cursor_bottom.png"; m_sliderpix = path +"general/vslider_cursor.png"; m_suppix = path + "general/vslider_btn_up.png"; m_sdownpix = path + "general/vslider_btn_down.png"; m_selection_left = path + "general/selection_left.png"; m_selection_right = path + "general/selection_right.png"; m_selection_mid = path + "general/selection_mid.png"; m_panel_tl = path + "general/box_top_left_mask.png"; m_panel_tr = path + "general/box_top_right_mask.png"; m_panel_bl = path + "general/box_bottom_left_mask.png"; m_panel_br = path + "general/box_bottom_right_mask.png"; m_panel_top = path + "general/box_top_mask.png"; m_panel_bottom = path + "general/box_bottom_mask.png"; m_panel_left = path + "general/box_left_mask.png"; m_panel_right = path + "general/box_right_mask.png"; setSliderThickness(m_sgroovepix.width());}void AStyle::polish(QWidget *w){ QWindowsStyle::polish(w); if(w->isA("QScrollBar")) { w->setMinimumWidth(m_sgroovepix.width()); w->setFixedWidth(m_sgroovepix.width()); }}void AStyle::drawSelection(QPainter *p, const QRect &r) const{ int x, y, w, h; r.rect(&x, &y, &w, &h); int tw= m_selection_left.width(); p->drawPixmap(x, y, m_selection_left); p->drawPixmap(x + w - tw, y, m_selection_right); p->drawTiledPixmap(QRect(x + tw, y, w - 2* tw, m_selection_left.height()), m_selection_mid);}void AStyle::drawPanel(QPainter *p, const QRect &area) const{ int x, y, w, h; area.rect(&x, &y, &w, &h); int pw= m_panel_tl.width(); int ph= m_panel_tl.height(); // fill panel p->fillRect(QRect(x + pw, y, w - 2* pw, h), QColor(255, 255, 255)); p->fillRect(QRect(x, y + ph, w, h -2* ph), QColor(255, 255, 255)); // draw corners p->drawPixmap(x, y, m_panel_tl); p->drawPixmap(x + w - pw, y, m_panel_tr); p->drawPixmap(x, y + h - ph, m_panel_bl); p->drawPixmap(x + w - pw, y + h - ph, m_panel_br); // draw edges p->drawTiledPixmap( x + m_panel_tl.width(), y, w - m_panel_tl.width() - m_panel_tr.width(), m_panel_top.height(), m_panel_top ); p->drawTiledPixmap( x + m_panel_bl.width(), y + h - m_panel_bottom.height(), w - m_panel_bl.width() - m_panel_br.width(), m_panel_bottom.height(), m_panel_bottom ); p->drawTiledPixmap( x + w - m_panel_tr.width(), y + m_panel_tr.height(), m_panel_right.width(), h - m_panel_tr.height() - m_panel_br.height(), m_panel_right ); p->drawTiledPixmap( x, y + + m_panel_tl.height(), m_panel_left.width(), h - m_panel_tl.height() - m_panel_bl.height(), m_panel_left );}void AStyle::scrollBarMetrics(const QScrollBar *s, int &smin, int &smax, int &slen, int &bdim){ QWindowsStyle::scrollBarMetrics(s, smin, smax, slen, bdim); bdim= m_suppix.height();}void AStyle::drawScrollBarControls(QPainter *p, const QScrollBar *s){ if(s == NULL) return; int sliderMin, sliderMax, sliderLength, buttonDim; scrollBarMetrics(s, sliderMin, sliderMax, sliderLength, buttonDim); int x, y, w, h; s->rect().rect(&x, &y, &w, &h); int y1= y; int y2= y + h - 1; if(s->backgroundPixmap() != NULL) p->drawTiledPixmap(s->rect(), *(s->backgroundPixmap())); p->drawPixmap(x, y1, m_suppix); y1+= m_suppix.height(); y2-= m_sdownpix.height(); p->drawPixmap(x, y2, m_sdownpix); p->drawTiledPixmap(QRect(x + 1, y1, w, y2 - y1 + 1), m_sgroovepix); int sh= sliderLength; int th= y2 - y1 - sh - 8; if(s->maxValue() != 0) y1+= th* s->value()/ s->maxValue() - 1; p->drawPixmap(x + 1, y1, m_sgroovetoppix); y1+= m_sgroovetoppix.height(); p->drawTiledPixmap(QRect(x + 1, y1, s->width(), sh), m_sliderpix); y1+= sh; p->drawPixmap(x +1, y1, m_sgroovebottompix);}const QString AStyle::iconpath(ICON_PATH);AStyle *AStyle::s_instance= NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -