| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #include "xtitlebar.h"
- XTitleBar::XTitleBar(QWidget *parent) :
- QWidget(parent)
- {
- initVariable();
- initUI();
- }
- XTitleBar::~XTitleBar()
- {
- delete m_pLabelIcon;
- delete m_pLabelTitle;
- delete m_pBtnClose;
- delete m_pBtnMin;
- delete m_pBtnMax;
- delete m_pLayout;
- }
- void XTitleBar::initVariable()
- {
- m_mouseMoveWindowFlag = false;
- m_pLabelIcon = new QLabel(this);
- m_pLabelTitle = new QLabel(this);
- m_pLabelTitle->setText("¼«ËÙºÅÂëħ·½");
- //m_pLabelIcon->setPixmap(QPixmap(":/common/appicon"));
- m_pBtnMax = new XImageButton(QPixmap(":/sysButton/max_button"),this);
- m_pBtnMin = new XImageButton(QPixmap(":/sysButton/min_button"),this);
- m_pBtnClose = new XImageButton(QPixmap(":/sysButton/close_button"),this);
- m_pLayout = new QHBoxLayout(this);
- this->setMouseTracking(true);
- const QObjectList &objList = children();
- for(int nIndex=0; nIndex<objList.count();++nIndex)
- {
- if(0==qstrcmp(objList.at(nIndex)->metaObject()->className(),"XImageButton"))
- {
- // ((XImageButton*)(objList.at(nIndex)))->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
- // ((XImageButton*)(objList.at(nIndex)))->setFixedHeight(19);
- // ((XImageButton*)(objList.at(nIndex)))->setFixedWidth(29);
- connect(((XImageButton*)(objList.at(nIndex))),SIGNAL(clicked()),this,SLOT(slotOnBtnClick()));
- }
- }
- }
- void XTitleBar::initUI()
- {
- this->setLayout(m_pLayout);
- m_pLabelIcon->setMaximumSize(19,19);
- m_pLabelIcon->setFixedHeight(19);
- m_pLabelTitle->setFixedHeight(19);
- this->setFixedHeight(25);
- m_pLabelIcon->setScaledContents(true);
- m_pLabelIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
- m_pLabelTitle->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
- m_pLabelTitle->setAlignment(Qt::AlignBottom);
- m_pLabelIcon->setAlignment(Qt::AlignBottom);
- m_pLayout->addWidget(m_pLabelIcon);
- m_pLayout->addWidget(m_pLabelTitle);
- m_pLayout->addStretch(1);
- m_pLayout->addWidget(m_pBtnMax);
- m_pLayout->addWidget(m_pBtnMin);
- m_pLayout->addWidget(m_pBtnClose);
- m_pLayout->setMargin(0);
- m_pLayout->setSpacing(0);
- setMouseTracking(true);
- this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
- }
- void XTitleBar::mouseMoveEvent(QMouseEvent *e)
- {
- // setCursor(Qt::ArrowCursor);
- // if((e->buttons() == Qt::LeftButton) && m_mouseMoveWindowFlag)
- // {
- // static QWidget* parent_widget = this->parentWidget();
- // QPoint parent_point = parent_widget->pos();
- // parent_point.setX(parent_point.x() + e->x() - m_mouseSrcPos.x());
- // parent_point.setY(parent_point.y() + e->y() - m_mouseSrcPos.y());
- // parent_widget->move(parent_point);
- // }
- e->ignore();
- }
- void XTitleBar::mousePressEvent(QMouseEvent *e)
- {
- // m_mouseMoveWindowFlag = false;
- // if (e->button() == Qt::LeftButton)
- // {
- //// if(e->y()<TITLEBAR_MARGIN||e->x()<TITLEBAR_MARGIN||rect().width()-e->x()<TITLEBAR_MARGIN)
- //// {
- //// e->ignore();
- //// m_mouseMoveWindowFlag = false;
- //// return;
- //// }
- // m_mouseSrcPos = e->pos();
- // m_mouseMoveWindowFlag = true;
- // }
- // e->ignore();
- e->ignore();
- }
- void XTitleBar::mouseReleaseEvent(QMouseEvent *e)
- {
- // m_mouseMoveWindowFlag = false;
- // e->ignore();
- }
- void XTitleBar::mouseDoubleClickEvent(QMouseEvent *e)
- {
- e->ignore();
- }
- void XTitleBar::slotOnBtnClick()
- {
- XImageButton *pBtn = (XImageButton*)(sender());
- if(pBtn==m_pBtnMin)
- {
- emit signalMin();
- }
- if(pBtn==m_pBtnMax)
- {
- emit signalMaxRestore();
- }
- if(pBtn==m_pBtnClose)
- {
- emit signalClose();
- }
- }
|