/*
* Copyright (C) 2019 明心 <imleizhang@qq.com>
* 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
lly202406
- 粉丝: 4267
最新资源
- 该文档为Google Earth Engine平台上的JavaScript脚本,用于处理和可视化Copernicus DEM数字高程模型数据
- 【地理信息系统】基于Google Earth Engine的数字高程模型分析:Copernicus DEM地形坡度与晕渲图可视化及导出系统实现
- junchaoIU-QCNLP-54680-1755347953964.zip
- 博客空间源码博客空间BF-Blog多用户v0.2.0-bf-blog0.2.0
- pdi-ce-9.5.0.1-261 百度网盘分享链接
- iimeta-iim-client-16804-1756641922451.zip
- 胖东来的销售数据集(17列,42817条记录)CSV
- 餐饮商铺数据集(16列,44512条记录)XLSX
- 餐饮商铺评论数据集(6列,212100条记录)XLSX
- 预制菜市场数据集(20列,10000条记录)CSV
- TikTok商品销售数据集(15列,200000条记录)CSV
- 餐饮商铺及评论数据集(16+6列,44512+212100条记录)XLSX
- 2025最新上海市12.5m数字高程模型DEM数据下载
- 基于Qt6跨平台GUI框架开发的TFTP文件传输客户端-实现TFTP协议文件上传下载功能-支持进度条显示错误信息吞吐量速度统计本地文件冲突处理-用于华中科技大学网络空间安全学院计算.zip
- 博客空间源码博客空间BlogCMS4.2.1.c-blogcms
- 2025最新上海市12.5m数字高程模型DEM数据TIF格式下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



