TMyFrame::TMyFrame(QWidget *p) : QFrame(p){ vLayout = new QVBoxLayout(this); vLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); hTopLayout = new QHBoxLayout(); hBottomLayout = new QHBoxLayout(); hTopLayout->setAlignment(Qt::AlignLeft); hBottomLayout->setAlignment(Qt::AlignLeft); vLayout->addLayout(hTopLayout); vLayout->addLayout(hBottomLayout);}void TMyFrame::addWidget(QWidget *w){ hTopLayout->addWidget(w);}
C++ (Qt)QVBoxLayout *mainLayout = new QVBoxLayout(this); QHBoxLayout *topLayout = new QHBoxLayout();QHBoxLayout *bottomLayout = new QHBoxLayout(); mainLayout->addLayout(topLayout);mainLayout->addLayout(bottomLayout);mainLayout->setAlignment(topLayout, Qt::AlignLeft);mainLayout->setAlignment(bottomLayout, Qt::AlignLeft);
class TMainDialog : public QMainWindow{ Q_OBJECT public: TMainDialog( QWidget *parent = NULL ); private: TMainWidget *MWgt_mainWidget;};//===================================================================================================class TMainWidget : public QWidget{ Q_OBJECT public: TMainWidget( QWidget *parent = NULL ); private: QVBoxLayout *qVBL_MainLayout; TTableWidgetDrop *TWD_DataTable; TFrameAbonent *TFr_Icons;};//===================================================================================================class TFrameAbonent : public QFrame{ Q_OBJECT public: TFrameAbonent( QWidget *parent = NULL ); bool addAbonent( int captionNum, int type ); bool clearAllAbonents(); bool showAbonent( int num ); public slots: bool hideAbonent( QString caption ); private: void updateLayout(); QList<TWidgetImage*> qLst_WidgetImage; QHBoxLayout *qHBL_topLayout; QHBoxLayout *qHBL_bottomLayout; QVBoxLayout *qVBL_layout;};//===================================================================================================TMainDialog::TMainDialog(QWidget *parent) : QMainWindow(parent){ QDesktopWidget dw; resize(dw.screenGeometry().width()/2, dw.screenGeometry().height()/2); MWgt_mainWidget = new TMainWidget(this); MWgt_mainWidget->resize(width(), height()); setCentralWidget(MWgt_mainWidget);}//===================================================================================================TMainWidget::TMainWidget( QWidget *parent ) : QWidget(parent){ qVBL_MainLayout = new QVBoxLayout(this); qVBL_MainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); //TWD_DataTable = new TTableWidgetDrop(MAX_TLK, MAX_TLK_ABONENT+1, this); //TWD_DataTable->setMinimumSize(580, 310); TFr_Icons = new TFrameAbonent(this); TFr_Icons->setMinimumSize(580, 170); TFr_Icons->setFrameStyle(QFrame::Panel | QFrame::Raised); qVBL_MainLayout->addWidget(TWD_DataTable); qVBL_MainLayout->addWidget(TFr_Icons); for(int i=9998; i <10020; i++) { TFr_Icons->addAbonent(i, AIR); } //TWD_DataTable->addTLKNet(0, R098, 0, 1, NORMAL, R805, 4, NORMAL); //TWD_DataTable->addTLKNet(2, KROSS, 2, 4, FAILED, BEKAS, 3, SELECTED); //connect(TWD_DataTable, SIGNAL(hideAbonent(QString)), TFr_Icons, SLOT(hideAbonent(QString)));}//===================================================================================================TFrameAbonent::TFrameAbonent( QWidget *parent ) : QFrame(parent){ qVBL_layout = new QVBoxLayout(this); qVBL_layout->setAlignment(Qt::AlignTop | Qt::AlignLeft); qHBL_topLayout = new QHBoxLayout(); qHBL_topLayout->setAlignment(Qt::AlignLeft); qHBL_bottomLayout = new QHBoxLayout(); qHBL_bottomLayout->setAlignment(Qt::AlignRight); qVBL_layout->addLayout(qHBL_topLayout); qVBL_layout->addLayout(qHBL_bottomLayout); qVBL_layout->setAlignment(qHBL_bottomLayout, Qt::AlignLeft);}//===================================================================================================//sort & updatevoid TFrameAbonent::updateLayout(){ if(qLst_WidgetImage.count()>MAX_ABONENT/2) { int hidden=0; int visible=0; for(int i=0; i <qHBL_topLayout->count(); i++) if(!(qHBL_topLayout->itemAt(i))->widget()->isVisible()) hidden++; int currentVisible = qHBL_topLayout->count()-hidden; qWarning("hidden = %d, currentVisible = %d", hidden, currentVisible); if(currentVisible<MAX_ABONENT/2) { for(int i=0; i <qHBL_bottomLayout->count(); i++) { TWidgetImage* wi =(TWidgetImage*)((qHBL_bottomLayout->itemAt(i))->widget()); if(wi->isVisible()) visible++; qHBL_bottomLayout->removeWidget(wi); qHBL_topLayout->addWidget(wi); i--; if(currentVisible + visible == MAX_ABONENT/2) break; } qWarning("< vis = %d", visible); } else if (currentVisible>MAX_ABONENT/2) { qWarning(">"); for(int i=qHBL_topLayout->count(); i>=0; i--) { TWidgetImage* wi =(TWidgetImage*)((qHBL_topLayout->itemAt(i))->widget()); if(wi->isVisible()) visible++; qHBL_topLayout->removeWidget(wi); qHBL_bottomLayout->addWidget(wi); i--; if(currentVisible-visible == MAX_ABONENT/2) break; } } }}//===================================================================================================bool TFrameAbonent::addAbonent( int captionNum, int type ){ if(qLst_WidgetImage.count()+1>MAX_ABONENT) return false; QString str; str.setNum(captionNum); qLst_WidgetImage.append( new TWidgetImageMove(ABN, type, -1, str.left(NUM_TEXT_ABN), str.mid(NUM_TEXT_ABN), this)); if(qLst_WidgetImage.count()<=MAX_ABONENT/2) qHBL_topLayout->addWidget(qLst_WidgetImage[qLst_WidgetImage.count()-1]);//, row, column); else qHBL_bottomLayout->addWidget(qLst_WidgetImage[qLst_WidgetImage.count()-1]);//, row, column); return true;}//===================================================================================================bool TFrameAbonent::showAbonent( int num ){ if(num<0 || num>qLst_WidgetImage.count()) return false; if(qLst_WidgetImage[num]->isVisible()) return false; qLst_WidgetImage[num]->show(); updateLayout(); return true;}