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