📄 spinbar.cpp
字号:
#include <qpainter.h>#include <qbitmap.h>#include <qapplication.h>#include <archos/screen.h>#include "style.h"#include "spinbar.h"#include "fontchooser.h"using namespace archos;Spinbar::Spinbar(QWidget *parent, int spinbar_length, int cursor_length) : QWidget(parent, "spin_bar", WRepaintNoErase) , m_length(spinbar_length) , m_cursor_length(cursor_length) , m_cursor_pos(0){ QString path = AStyle::iconpath + Screen::prefix(); m_cursor_left_border = path + "general/spinbar_cursor_leftborder.png"; m_cursor_left = path + "general/spinbar_cursor_left.png"; m_empty_left = path + "general/spinbar_empty_left.png"; m_cursor = path + "general/spinbar_cursor.png"; m_empty = path + "general/spinbar_empty.png"; m_empty_right = path + "general/spinbar_empty_right.png"; m_cursor_right = path + "general/spinbar_cursor_right.png"; m_cursor_right_border = path + "general/spinbar_cursor_rightborder.png"; QFont font = qApp->font(); if (Screen::mode() == wqvga || Screen::mode() == qvga) { font.setPointSize(16); } else if ( Screen::mode() == wvga ) { font.setPointSize(22); } else { // tv font.setPointSize(18); } setFont(font); connect(&m_timer, SIGNAL(timeout()), this, SLOT(spin())); resize(m_length, m_cursor.height()); polish();};Spinbar::~Spinbar(){ stop();}void Spinbar::polish(){ QBitmap mask(size()); QPainter p(&mask); p.drawPixmap(0, 0, m_empty_left); int len = m_length - m_empty_left.width() - m_empty_right.width(); int i; for (i = 0; i < len; i++) { p.drawPixmap(m_empty_left.width() + i, 0, m_empty); } p.drawPixmap(m_empty_left.width() + i, 0, m_empty_right); setMask(mask);}void Spinbar::start(void){ polish(); m_cursor_pos = 0; m_timer.start(50);}void Spinbar::setText(QString text) { m_text = text;}void Spinbar::stop(void){ m_timer.stop();}void Spinbar::spin(){ m_cursor_pos = (m_cursor_pos + 1) % (m_length + m_cursor_length); update();}void Spinbar::paintEvent(QPaintEvent *evt){ QRect area(rect()); QPixmap pix(area.size()); QPainter p(&pix, this); //QPainter p(this); int cursor_start = m_cursor_pos - m_cursor_length; if (cursor_start < 0) cursor_start = 0; int cursor_end = m_cursor_pos; int cursor_len = cursor_end - cursor_start; if (cursor_end <= m_cursor_length) { for (int i = 0; i < cursor_len; i++) { p.drawPixmap(cursor_start + i, 0, m_cursor); } p.drawPixmap(0, 0, m_cursor_left_border, 0, 0, cursor_len); for (int i = 0; i < m_length - cursor_end; i++) { p.drawPixmap(cursor_end + i, 0, m_empty); } if (cursor_end > m_cursor_left_border.width() + 1) { p.drawPixmap(m_cursor_pos - m_cursor_right.width(), 0, m_cursor_right); } p.drawPixmap(m_length - m_empty_right.width(), 0, m_empty_right); } else if (cursor_start > 0 && cursor_end < m_length) { for (int i = 0; i < cursor_start; i++) { p.drawPixmap(i, 0, m_empty); } for (int i = 0; i < cursor_len; i++) { p.drawPixmap(cursor_start + i, 0, m_cursor); } if (cursor_start > m_empty_right.width()) { p.drawPixmap(0, 0, m_empty_left); p.drawPixmap(cursor_start, 0, m_cursor_left); } else { p.drawPixmap(0, 0, m_empty_left, 0, 0, cursor_start); p.drawPixmap(cursor_start, 0, m_cursor_left_border, cursor_start, 0, m_empty_right.width() - cursor_start); } for (int i = 0; i < m_length - cursor_end; i++) { p.drawPixmap(cursor_end + i, 0, m_empty); } if (cursor_end < m_length - m_cursor_right.width()) { p.drawPixmap(cursor_end - m_cursor_right.width(), 0, m_cursor_right); p.drawPixmap(m_length - m_empty_right.width(), 0, m_empty_right); } } else { int i; for (i = 0; i < m_cursor_pos - m_cursor_length; i++) { p.drawPixmap(i, 0, m_empty); } for (; i < m_length; i++) { p.drawPixmap(i, 0, m_cursor); } p.drawPixmap(m_cursor_pos - m_cursor_length, 0, m_cursor_left); p.drawPixmap(0, 0, m_empty_left); } if (!m_text.isEmpty()) { p.drawText(0, 1, width(), height(), AlignVCenter | AlignHCenter, m_text); } QPainter screen(this); screen.drawPixmap(area.topLeft(), pix);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -