Reworked to use a qtabwidget: better cross-os look
This commit is contained in:
parent
3af5804073
commit
fac44966fd
2 changed files with 36 additions and 33 deletions
|
@ -8,15 +8,13 @@
|
|||
#include "settingscache.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabBar>
|
||||
|
||||
CardFrame::CardFrame(int width, int height,
|
||||
const QString &cardName, QWidget *parent)
|
||||
: QFrame(parent)
|
||||
: QTabWidget(parent)
|
||||
, info(0)
|
||||
, cardTextOnly(false)
|
||||
{
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
setMaximumWidth(width);
|
||||
setMinimumWidth(width);
|
||||
setMinimumHeight(height);
|
||||
|
@ -24,20 +22,28 @@ CardFrame::CardFrame(int width, int height,
|
|||
pic = new CardInfoPicture(width);
|
||||
text = new CardInfoText();
|
||||
|
||||
tabBar = new QTabBar(this);
|
||||
tabBar->setDrawBase(false);
|
||||
tabBar->insertTab(ImageOnlyView, QString());
|
||||
tabBar->insertTab(TextOnlyView, QString());
|
||||
tabBar->insertTab(ImageAndTextView, QString());
|
||||
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(setViewMode(int)));
|
||||
tab1 = new QWidget(this);
|
||||
tab2 = new QWidget(this);
|
||||
tab3 = new QWidget(this);
|
||||
insertTab(ImageOnlyView, tab1, QString());
|
||||
insertTab(TextOnlyView, tab2, QString());
|
||||
insertTab(ImageAndTextView, tab3, QString());
|
||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(setViewMode(int)));
|
||||
|
||||
QVBoxLayout * layout = new QVBoxLayout();
|
||||
layout->addWidget(tabBar);
|
||||
layout->addWidget(pic);
|
||||
layout->addWidget(text);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
setLayout(layout);
|
||||
tab1Layout = new QVBoxLayout();
|
||||
tab1Layout->setContentsMargins(0, 0, 0, 0);
|
||||
tab1Layout->setSpacing(0);
|
||||
tab1->setLayout(tab1Layout);
|
||||
|
||||
tab2Layout = new QVBoxLayout();
|
||||
tab2Layout->setContentsMargins(0, 0, 0, 0);
|
||||
tab2Layout->setSpacing(0);
|
||||
tab2->setLayout(tab2Layout);
|
||||
|
||||
tab3Layout = new QVBoxLayout();
|
||||
tab3Layout->setContentsMargins(0, 0, 0, 0);
|
||||
tab3Layout->setSpacing(0);
|
||||
tab3->setLayout(tab3Layout);
|
||||
|
||||
setViewMode(settingsCache->getCardInfoViewMode());
|
||||
|
||||
|
@ -46,29 +52,26 @@ CardFrame::CardFrame(int width, int height,
|
|||
|
||||
void CardFrame::retranslateUi()
|
||||
{
|
||||
tabBar->setTabText(ImageOnlyView, tr("Image"));
|
||||
tabBar->setTabText(TextOnlyView, tr("Description"));
|
||||
tabBar->setTabText(ImageAndTextView, tr("Both"));
|
||||
setTabText(ImageOnlyView, tr("Image"));
|
||||
setTabText(TextOnlyView, tr("Description"));
|
||||
setTabText(ImageAndTextView, tr("Both"));
|
||||
}
|
||||
|
||||
void CardFrame::setViewMode(int mode)
|
||||
{
|
||||
if(tabBar->currentIndex() != mode)
|
||||
tabBar->setCurrentIndex(mode);
|
||||
if(currentIndex() != mode)
|
||||
setCurrentIndex(mode);
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case ImageOnlyView:
|
||||
pic->setVisible(true);
|
||||
text->setVisible(false);
|
||||
break;
|
||||
case TextOnlyView:
|
||||
pic->setVisible(false);
|
||||
text->setVisible(true);
|
||||
tab1Layout->addWidget(pic);
|
||||
tab2Layout->addWidget(text);
|
||||
break;
|
||||
case ImageAndTextView:
|
||||
pic->setVisible(true);
|
||||
text->setVisible(true);
|
||||
tab3Layout->addWidget(pic);
|
||||
tab3Layout->addWidget(text);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
#ifndef CARDFRAME_H
|
||||
#define CARDFRAME_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QTabWidget>
|
||||
|
||||
class AbstractCardItem;
|
||||
class CardInfo;
|
||||
class CardInfoPicture;
|
||||
class CardInfoText;
|
||||
class QTabBar;
|
||||
class QVBoxLayout;
|
||||
|
||||
class CardFrame : public QFrame {
|
||||
class CardFrame : public QTabWidget {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QTabBar * tabBar;
|
||||
CardInfo *info;
|
||||
CardInfoPicture *pic;
|
||||
CardInfoText *text;
|
||||
bool cardTextOnly;
|
||||
QWidget *tab1, *tab2, *tab3;
|
||||
QVBoxLayout *tab1Layout, *tab2Layout, *tab3Layout;
|
||||
|
||||
public:
|
||||
enum ViewMode { ImageOnlyView, TextOnlyView, ImageAndTextView };
|
||||
|
@ -25,7 +26,6 @@ public:
|
|||
CardFrame(int width, int height, const QString &cardName = QString(),
|
||||
QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
|
||||
public slots:
|
||||
void setCard(CardInfo *card);
|
||||
void setCard(const QString &cardName);
|
||||
|
|
Loading…
Reference in a new issue