brough back to MacOSX the fit to width slider //ugly solution

This commit is contained in:
Luis Ángel San Martín
2014-11-10 17:59:57 +01:00
parent 1ae1f04eb7
commit e5fe87142f
6 changed files with 150 additions and 66 deletions

View File

@ -488,13 +488,23 @@ void MainWindowViewer::createToolBars()
//comicToolBar->addAction(adjustWidth);
#ifdef Q_OS_MAC
sliderAction = new YACReaderSlider(this);
sliderAction->hide();
comicToolBar->addAction(adjustWidthAction);
QAction * action = comicToolBar->addFitToWidthSlider(adjustWidthAction);
connect(action,SIGNAL(triggered()),this,SLOT(toggleFitToWidthSlider()));
#else
QMenu * menu = new QMenu();
sliderAction = new YACReaderSliderAction(this);
sliderAction = new YACReaderSliderAction(this);
menu->setAutoFillBackground(false);
menu->setStyleSheet(" QMenu {background:transparent; border: 0px;padding: 0px; }"
);
@ -503,16 +513,15 @@ void MainWindowViewer::createToolBars()
tb2->addAction(adjustWidthAction);
tb2->setMenu(menu);
connect(sliderAction,SIGNAL(fitToWidthRatioChanged(float)),viewer,SLOT(updateFitToWidthRatio(float)));
connect(optionsDialog,SIGNAL(fitToWidthRatioChanged(float)),sliderAction,SLOT(updateFitToWidthRatio(float)));
//tb2->addAction();
tb2->setPopupMode(QToolButton::MenuButtonPopup);
tb2->setDefaultAction(adjustWidthAction);
comicToolBar->addWidget(tb2);
#endif
connect(sliderAction,SIGNAL(fitToWidthRatioChanged(float)),viewer,SLOT(updateFitToWidthRatio(float)));
connect(optionsDialog,SIGNAL(fitToWidthRatioChanged(float)),sliderAction,SLOT(updateFitToWidthRatio(float)));
comicToolBar->addAction(adjustHeightAction);
comicToolBar->addAction(adjustToFullSizeAction);
comicToolBar->addAction(leftRotationAction);
@ -1129,6 +1138,20 @@ void MainWindowViewer::setUpShortcutsManagement()
ShortcutsManager::getShortcutsManager().registerActions(allActions);
}
#include "QsLog.h"
void MainWindowViewer::toggleFitToWidthSlider()
{
if(sliderAction->isVisible())
{
sliderAction->hide();
}
else
{
sliderAction->move(250,0);
sliderAction->show();
}
}
void MainWindowViewer::changeFit()

View File

@ -22,6 +22,7 @@ class HelpAboutDialog;
class HttpVersionChecker;
class ShortcutsDialog;
class YACReaderSliderAction;
class YACReaderSlider;
class EditShortcutsDialog;
class MainWindowViewer : public QMainWindow
@ -58,6 +59,10 @@ class EditShortcutsDialog;
void checkNewVersion();
void processReset();
void setUpShortcutsManagement();
#ifdef Q_OS_MAC
void toggleFitToWidthSlider();
#endif
/*void viewComic();
void prev();
void next();
@ -73,7 +78,7 @@ class EditShortcutsDialog;
QString currentDirectory;
QString currentDirectoryImgDest;
//!Widgets
Viewer * viewer;
Viewer * viewer;
//GoToDialog * goToDialog;
OptionsDialog * optionsDialog;
HelpAboutDialog * had;
@ -116,8 +121,11 @@ class EditShortcutsDialog;
QAction *showFlowAction;
QAction *showEditShortcutsAction;
YACReaderSliderAction * sliderAction;
#ifdef Q_OS_MAC
YACReaderSlider * sliderAction;
#else
YACReaderSliderAction * sliderAction;
#endif
HttpVersionChecker * versionChecker;
QString previousComicPath;

View File

@ -9,70 +9,86 @@
YACReaderSliderAction::YACReaderSliderAction (QWidget * parent)
:QWidgetAction (parent) {
QWidget* pWidget = new QWidget (NULL);
QHBoxLayout* pLayout = new QHBoxLayout();
widget = new YACReaderSlider();
setDefaultWidget(widget);
pLayout->addStretch();
percentageLabel = new QLabel ("100%");
percentageLabel->setStyleSheet("QLabel { color : white; }");
percentageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
pLayout->addWidget (percentageLabel);
slider = new QSlider(NULL);
slider->setOrientation(Qt::Horizontal);
pLayout->addWidget (slider);
QString sliderCSS =
"QSlider::sub-page:horizontal {background-image: url(:/images/sliderSubPage.png); border: 0px; margin-left: 18px;}"
"QSlider::add-page:horizontal {background-image: url(:/images/sliderAddPage.png); border: 0px; margin-right: 25px;}"
"QSlider::handle:horizontal {image: url(:/images/sliderHandle.png); width: 31px;height:45px; }"
"QSlider::groove:horizontal {border-image:url(:/images/sliderGround.png); border-left:-2px; border-right:0;}"
;
slider->setStyleSheet(sliderCSS);
slider->setFixedSize(218,45);
QLabel* imgLabel = new QLabel(pWidget);
QPixmap p(":/images/sliderBackground.png");
imgLabel->resize(p.size());
imgLabel->setPixmap(p);
pLayout->setMargin(0);
pLayout->setSpacing(0);
pLayout->setStretchFactor(percentageLabel,1);
pLayout->setStretchFactor(slider,0);
pWidget->setLayout (pLayout);
pWidget->setAutoFillBackground(false);
pWidget->setMinimumSize(276,45);
setDefaultWidget(pWidget);
slider->setMinimum(50);
slider->setMaximum(100);
slider->setPageStep(5);
int value = Configuration::getConfiguration().getFitToWidthRatio()*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int)));
connect(widget,SIGNAL(fitToWidthRatioChanged(float)),this,SIGNAL(fitToWidthRatioChanged(float)));
}
void YACReaderSliderAction::updateText(int value)
{
percentageLabel->setText(QString("%1 %").arg(value));
Configuration::getConfiguration().setFitToWidthRatio(value/100.0);
emit(fitToWidthRatioChanged(value / 100.0f));
widget->updateText(value);
}
void YACReaderSliderAction::updateFitToWidthRatio(float v)
{
int value = v*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
widget->updateFitToWidthRatio(v);
}
YACReaderSlider::YACReaderSlider(QWidget *parent)
:QWidget(parent)
{
QHBoxLayout* pLayout = new QHBoxLayout();
pLayout->addStretch();
percentageLabel = new QLabel ("100%");
percentageLabel->setStyleSheet("QLabel { color : white; }");
percentageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
pLayout->addWidget (percentageLabel);
slider = new QSlider(NULL);
slider->setOrientation(Qt::Horizontal);
pLayout->addWidget (slider);
QString sliderCSS =
"QSlider::sub-page:horizontal {background-image: url(:/images/sliderSubPage.png); border: 0px; margin-left: 18px;}"
"QSlider::add-page:horizontal {background-image: url(:/images/sliderAddPage.png); border: 0px; margin-right: 25px;}"
"QSlider::handle:horizontal {image: url(:/images/sliderHandle.png); width: 31px;height:45px; }"
"QSlider::groove:horizontal {border-image:url(:/images/sliderGround.png); border-left:-2px; border-right:0;}"
;
slider->setStyleSheet(sliderCSS);
slider->setFixedSize(218,45);
QLabel* imgLabel = new QLabel(this);
QPixmap p(":/images/sliderBackground.png");
imgLabel->resize(p.size());
imgLabel->setPixmap(p);
pLayout->setMargin(0);
pLayout->setSpacing(0);
pLayout->setStretchFactor(percentageLabel,1);
pLayout->setStretchFactor(slider,0);
setLayout (pLayout);
setAutoFillBackground(false);
setMinimumSize(276,45);
slider->setMinimum(50);
slider->setMaximum(100);
slider->setPageStep(5);
int value = Configuration::getConfiguration().getFitToWidthRatio()*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int)));
}
void YACReaderSlider::updateText(int value)
{
percentageLabel->setText(QString("%1 %").arg(value));
Configuration::getConfiguration().setFitToWidthRatio(value/100.0);
emit(fitToWidthRatioChanged(value / 100.0f));
}
void YACReaderSlider::updateFitToWidthRatio(float v)
{
int value = v*100;
slider->setValue(value);
percentageLabel->setText(QString("%1 %").arg(value));
}

View File

@ -6,12 +6,31 @@
class QLabel;
class QSlider;
class YACReaderSlider : public QWidget
{
Q_OBJECT
private:
QLabel * percentageLabel;
QSlider * slider;
public:
YACReaderSlider (QWidget * parent = 0);
public slots:
void updateText(int value);
void updateFitToWidthRatio(float v);
signals:
void fitToWidthRatioChanged(float value);
};
class YACReaderSliderAction : public QWidgetAction
{
Q_OBJECT
private:
QLabel * percentageLabel;
QSlider * slider;
YACReaderSlider * widget;
public:

View File

@ -64,6 +64,10 @@ public:
//hacks everywhere
//convenience method for YACReaderLibrary search edit
YACReaderMacOSXSearchLineEdit *addSearchEdit();
//convenience method for showing the fit to width slider in MacOSX
QAction * addFitToWidthSlider(QAction * attachToAction);
//convenience method for switching the icon of the view selector
void updateViewSelectorIcon(const QIcon & icon);

View File

@ -280,6 +280,20 @@ YACReaderMacOSXSearchLineEdit * YACReaderMacOSXToolbar::addSearchEdit()
return searchEdit;
}
QAction *YACReaderMacOSXToolbar::addFitToWidthSlider(QAction *attachToAction)
{
QMacToolBarItem *toolBarItem = addItem(attachToAction->icon(),"fit to width slider");
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
actions.insert(QString::fromNSString(nativeItem.itemIdentifier),attachToAction);
QAction * action = new QAction("",attachToAction->parent());
connect(toolBarItem,SIGNAL(activated()), action, SIGNAL(triggered()));
return action;
}
void YACReaderMacOSXToolbar::updateViewSelectorIcon(const QIcon &icon)
{
if(viewSelector)