/*
* Copyright (C) 2019 明心 <[email protected]>
* All rights reserved.
*
* This program is an open-source software; and it is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
* This program is not a free software; so you can not redistribute it(include
* binary form and source code form) without my authorization. And if you
* need use it for any commercial purpose, you should first get commercial
* authorization from me, otherwise there will be your's legal&credit risks.
*
*/
#include <gCtrlStyle.h>
#include "gCtrlListBox.h"
#include <gConstDefine.h>
#include <gGlobal.h>
GCtrlListBoxItem::GCtrlListBoxItem ( const GString& str, GCtrlForm* frm, GMItem* parent, const char* name )
:GMCtrlItem ( frm, parent, name ),
m_txt ( str, frm, this, "listBoxText" )
{
m_txt.setTextFlags ( Giveda::AlignVCenter );
}
void GCtrlListBoxItem::paintEvent ( GPainter& p )
{
m_txt.draw ( p );
}
bool GCtrlListBoxItem::fwKeyPressEvent ( GKeyEvent *e )
{
bool bRetVal = true;
switch ( e->key() )
{
case Giveda::Key_Return:
{
GCtrlListBox* pBox = ( GCtrlListBox* ) parent();
pBox->emitSelected ( this );
}
break;
default:
bRetVal = false;
break;
}
return bRetVal;
}
void GCtrlListBoxItem::setGeometry ( int x, int y, int w, int h )
{
GMItem::setGeometry ( x,y,w,h );
m_txt.setSize ( width(), height() );
}
GCtrlListBoxPixmap::GCtrlListBoxPixmap ( const GPixmap& pm, const GString& str, GCtrlForm* frm, GMItem* parent, const char* name )
:GCtrlListBoxItem ( str, frm, parent, name ), m_pix ( pm, frm, this, "listBoxPixmap" )
{
}
void GCtrlListBoxPixmap::paintEvent ( GPainter& p )
{
m_pix.draw ( p );
m_txt.draw ( p );
}
void GCtrlListBoxPixmap::setGeometry ( int x, int y, int w, int h )
{
GMItem::setGeometry ( x,y,w,h );
int nTmp = height() - m_pix.height();
if ( nTmp > 1 )
{
m_pix.setY ( nTmp/2 );
}
m_txt.setGeometry ( m_pix.width(), 0, width()-m_pix.width(), height() );
}
class GCtrlListBoxMhL
{
public:
GCtrlListBoxMhL ( GCtrlForm* frm, GMItem* parent, GCtrlListBox *lb)
:m_imgFocusIn ( frm, parent, "listBoxFocusIn" ), m_imgFocusOut ( frm, parent, "listBoxFocusOut" ), m_timerForShowItemInfo ( lb ), m_itemTxtColor ( 255,255,255 ), m_itemTxtFont ( "Sans", 20 )
{}
GPtrList<GCtrlListBoxItem> m_itemList;
GMImage m_imgFocusIn;
GMImage m_imgFocusOut;
GTimer m_timerForShowItemInfo;
unsigned int m_nCurItemIndex;
bool m_bIsNeedDoLayout;
bool m_bIsNeedShowItemInfo;
bool m_bSendHighLighted;
unsigned int m_nDrawFrom;
unsigned int m_nDrawTo;
unsigned int m_nMaxWofItem;
unsigned int m_nMaxHofItem;
int m_nColumnNums;
int m_nRowNums;
GColor m_itemTxtColor;
GFont m_itemTxtFont;
bool m_bScrollEnabled;
int m_nPreviousItemKey;
int m_nNextItemKey;
};
GCtrlListBox::GCtrlListBox ( GCtrlForm* frm, GMItem* parent, const char* name )
:GMContainerItem ( frm, parent, name )
{
lbLqH = new GCtrlListBoxMhL(frm, parent, this );
frm->appendItem ( this );
lbLqH->m_nDrawFrom = 0;
lbLqH->m_nColumnNums = 1;
setRowNums ( 3 );
connect ( &lbLqH->m_timerForShowItemInfo,
lbLqH->m_timerForShowItemInfo.timeout, this, &GCtrlListBox::slotFocusChangedTo );
connect ( this, this->loseFocus, this, &GCtrlListBox::slotLoseFocus );
connect ( this, this->getFocus, this, &GCtrlListBox::slotGetFocus );
lbLqH->m_nCurItemIndex = 0;
lbLqH->m_bIsNeedDoLayout = true;
lbLqH->m_bIsNeedShowItemInfo = true;
lbLqH->m_bSendHighLighted = false;
GCtrlDefaultAppStyle* pAppStyle = getDefaultAppStyle();
GCtrlItemStyle* pStyle=NULL;
while ( NULL== ( pStyle=pAppStyle->itemStyle ( className() ) ) )
{
pAppStyle->appendListBoxStyle();
}
lbLqH->m_imgFocusIn.setImage ( pStyle->pixmap ( lbLqH->m_imgFocusIn.name() ) );
lbLqH->m_imgFocusOut.setImage ( pStyle->pixmap ( lbLqH->m_imgFocusOut.name() ) );
lbLqH->m_bScrollEnabled = true;
lbLqH->m_nPreviousItemKey = Giveda::Key_Up;
lbLqH->m_nNextItemKey = Giveda::Key_Down;
}
GCtrlListBox::~GCtrlListBox()
{
lbLqH->m_itemList.clear();
delete lbLqH;
}
void GCtrlListBox::paintEvent ( GPainter& p )
{
if ( lbLqH->m_itemList.isEmpty() )
{
return;
}
int nDrawTo = lbLqH->m_itemList.count()-1<lbLqH->m_nDrawTo ? lbLqH->m_itemList.count()-1 : lbLqH->m_nDrawTo;
GCtrlListBoxItem* pItem=NULL;
if ( lbLqH->m_bIsNeedDoLayout )
{
lbLqH->m_itemList.at ( lbLqH->m_nDrawFrom )->setGeometry ( 0, 0, lbLqH->m_nMaxWofItem, lbLqH->m_nMaxHofItem );
lbLqH->m_itemList.at ( lbLqH->m_nDrawFrom )->getTxt()->setColor ( lbLqH->m_itemTxtColor );
lbLqH->m_itemList.at ( lbLqH->m_nDrawFrom )->getTxt()->setFont ( lbLqH->m_itemTxtFont );
int nBottomEdge = lbLqH->m_nMaxHofItem* ( lbLqH->m_nRowNums-1 );
for ( int j=lbLqH->m_nDrawFrom; j<nDrawTo; j++ )
{
pItem = lbLqH->m_itemList.at ( j+1 );
if ( lbLqH->m_itemList.at ( j )->y() == nBottomEdge )
{
pItem->setGeometry ( lbLqH->m_itemList.at ( j )->x() +lbLqH->m_nMaxWofItem, 0, lbLqH->m_nMaxWofItem, lbLqH->m_nMaxHofItem );
}
else
{
pItem->setGeometry ( lbLqH->m_itemList.at ( j )->x(), lbLqH->m_itemList.at ( j )->y() +lbLqH->m_nMaxHofItem, lbLqH->m_nMaxWofItem, lbLqH->m_nMaxHofItem );
}
pItem->getTxt()->setColor ( lbLqH->m_itemTxtColor );
pItem->getTxt()->setFont ( lbLqH->m_itemTxtFont );
}
lbLqH->m_bIsNeedDoLayout = false;
}
if ( hasFocus() )
{
lbLqH->m_imgFocusIn.setGeometry ( lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex )->x(), lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex )->y(), lbLqH->m_nMaxWofItem, lbLqH->m_nMaxHofItem );
lbLqH->m_imgFocusIn.draw ( p );
}
else
{
lbLqH->m_imgFocusOut.setGeometry ( lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex )->x(), lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex )->y(), lbLqH->m_nMaxWofItem, lbLqH->m_nMaxHofItem );
lbLqH->m_imgFocusOut.draw ( p );
}
for ( int j=lbLqH->m_nDrawFrom; j<=nDrawTo; j++ )
{
pItem = lbLqH->m_itemList.at ( j );
p.save();
p.translate ( pItem->x(), pItem->y() );
pItem->draw ( p );
p.restore();
}
if ( lbLqH->m_bSendHighLighted )
{
highlighted_pI.emit ( lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex ) );
highlighted_pi.emit ( lbLqH->m_nCurItemIndex );
lbLqH->m_bSendHighLighted = false;
}
if ( lbLqH->m_bIsNeedShowItemInfo )
{
lbLqH->m_timerForShowItemInfo.start ( 1000, true );
lbLqH->m_bIsNeedShowItemInfo = false;
}
}
bool GCtrlListBox::fwKeyPressEvent ( GKeyEvent* e )
{
mpFocus = lbLqH->m_itemList.at ( lbLqH->m_nCurItemIndex );
if ( mpFocus )
{
if ( true == mpFocus->fwKeyPress ( e ) )
{
return true;
}
}
int nKey=e->key();
bool bRetVal = true;
if ( nKey == lbLqH->m_nPreviousItemKey )
{
bRetVal = moveFocusUp();
if ( true == bRetVal )
{
return true;
}
}
if ( nKey == lbLqH->m_nNextItemKey )
{
bRetVal = moveFocusDown();
if ( true == bRetVal )
{
return true;
}
}
switch ( nKey )
{
case Giveda::Key_Left:
bRetVal = moveFocusLeft();
break;
case Giveda::Key_Right:
bRetVal = moveFocusRight();
break;
default:
bRetVal = false;
break;
}
return bRetVal;
}
void GCtrlListBox::insertItem ( GCtrlListBoxItem* pItem, int index )
{
if ( index<0 )
{
lbLqH->m_itemList.append ( pItem
没有合适的资源?快使用搜索试试~ 我知道了~
GOSP-硬件开发资源

共726个文件
html:375个
js:129个
cpp:60个

需积分: 1 0 下载量 141 浏览量
2025-08-15
07:54:25
上传
评论
收藏 11.85MB ZIP 举报
温馨提示
QtAPIKBQtQtQtGUISoC//MCU/TV/STB///linux/framebuffer/GUI framework/GUI library///
资源推荐
资源详情
资源评论
















格式:zip 资源大小:9.0MB







格式:zip 资源大小:9.0MB





收起资源包目录





































































































共 726 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论


lly202406
- 粉丝: 4234
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 数字电子技术存储器与可编程逻辑器件习题及答案.doc
- flash动画教学的主题构思和基本技法.doc
- 未成年人互联网大额交易效力浅析.docx
- 基于区块链技术的移动端金融平台设计与开发.docx
- TD-LTE无线网络规划及性能探究.docx
- 2012年计算机等级历年考试三级网络技术.doc
- 嵌入式系统开发及试验教学系统.ppt
- 数字电路制作20110915.jsp.doc
- C语言一日一学第5课——选择结构程序设计方案.doc
- 大数据环境下高校图书馆员队伍建设研究-以金陵科技学院图书馆为例.docx
- 计算机在机械和电子控制产业领域中的应用.docx
- 腾讯分布式数据库TDSQL技术介绍.pptx
- 计算机网络技术课程设计教程正文.doc
- vcos_apps-智能车资源
- lanqiao-蓝桥杯资源
- 基于高中生视角的互联网金融的法律监管研究.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
