mirror of
https://github.com/YACReader/yacreader
synced 2025-07-27 01:15:07 -04:00
a?adido nuevo widget que sustituye al combo box de las bibliotecas
This commit is contained in:
@ -16,7 +16,9 @@ HEADERS += $$PWD/help_about_dialog.h \
|
||||
$$PWD/yacreader_deleting_progress.h \
|
||||
$$PWD/yacreader_table_view.h \
|
||||
$$PWD/yacreader_social_dialog.h \
|
||||
$$PWD/yacreader_sidebar.h
|
||||
$$PWD/yacreader_sidebar.h \
|
||||
$$PWD/yacreader_library_list_widget.h \
|
||||
$$PWD/yacreader_library_item_widget.h \
|
||||
|
||||
|
||||
SOURCES += $$PWD/help_about_dialog.cpp \
|
||||
@ -34,4 +36,6 @@ SOURCES += $$PWD/help_about_dialog.cpp \
|
||||
$$PWD/yacreader_deleting_progress.cpp \
|
||||
$$PWD/yacreader_table_view.cpp \
|
||||
$$PWD/yacreader_social_dialog.cpp \
|
||||
$$PWD/yacreader_sidebar.cpp
|
||||
$$PWD/yacreader_sidebar.cpp \
|
||||
$$PWD/yacreader_library_list_widget.cpp \
|
||||
$$PWD/yacreader_library_item_widget.cpp \
|
137
custom_widgets/yacreader_library_item_widget.cpp
Normal file
137
custom_widgets/yacreader_library_item_widget.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
#include "yacreader_library_item_widget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QMouseEvent>
|
||||
|
||||
YACReaderLibraryItemWidget::YACReaderLibraryItemWidget(QString n/*ame*/, QString p/*ath*/, QWidget *parent) :
|
||||
QWidget(parent),name(n),path(p),isSelected(false)
|
||||
{
|
||||
QHBoxLayout * mainLayout = new QHBoxLayout;
|
||||
mainLayout->setMargin(0);
|
||||
mainLayout->setSpacing(0);
|
||||
|
||||
//installEventFilter(this);
|
||||
|
||||
QPixmap iconPixmap(":/images/libraryIcon.png");
|
||||
icon = new QLabel(this);
|
||||
icon->setAutoFillBackground(true);
|
||||
icon->setPixmap(iconPixmap);
|
||||
nameLabel = new QLabel(name,this);
|
||||
|
||||
options = new QToolButton(this);
|
||||
options->setIcon(QIcon(":/images/libraryOptions.png"));
|
||||
options->setHidden(true);
|
||||
options->setFixedWidth(18);
|
||||
options->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum);
|
||||
options->setStyleSheet("QToolButton {border:none;}");
|
||||
/*up = new QToolButton(this);
|
||||
up->setIcon(QIcon(":/images/libraryUp.png"));
|
||||
up->setHidden(true);
|
||||
up->setFixedWidth(18);
|
||||
up->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum);
|
||||
|
||||
down = new QToolButton(this);
|
||||
down->setIcon(QIcon(":/images/libraryDown.png"));
|
||||
down->setHidden(true);
|
||||
down->setFixedWidth(18);
|
||||
down->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum);*/
|
||||
|
||||
|
||||
mainLayout->addWidget(icon);
|
||||
mainLayout->addWidget(nameLabel,Qt::AlignLeft);
|
||||
mainLayout->addStretch();
|
||||
mainLayout->addWidget(options);
|
||||
/*mainLayout->addWidget(up);
|
||||
mainLayout->addWidget(down);*/
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
//QString styleSheet = " background-color:#454545; border-top: 1px solid #454545;border-bottom: 1px solid #454545;";
|
||||
//setStyleSheet(styleSheet);
|
||||
|
||||
|
||||
QString iconStyleSheet = "QLabel {padding:0 0 0 24px; margin:0px}";
|
||||
icon->setStyleSheet(iconStyleSheet);
|
||||
|
||||
QString nameLabelStyleSheet = "QLabel {padding:0 0 0 3px; margin:0px;}";
|
||||
nameLabel->setStyleSheet(nameLabelStyleSheet);
|
||||
|
||||
setMinimumHeight(20);
|
||||
}
|
||||
|
||||
void YACReaderLibraryItemWidget::showUpDownButtons(bool show)
|
||||
{
|
||||
up->setHidden(!show);
|
||||
down->setHidden(!show);
|
||||
}
|
||||
|
||||
/*
|
||||
bool YACReaderLibraryItemWidget::eventFilter(QObject *object, QEvent *event){
|
||||
if(!isSelected && object==this && (event->type()==QEvent::Enter))
|
||||
{
|
||||
QString styleSheet = "background-color:#5E5E5E; border-top: 1px solid #5E5E5E;border-bottom: 1px solid #5E5E5E; ";
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
up->setHidden(false);
|
||||
down->setHidden(false);
|
||||
options->setHidden(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
if(!isSelected && object==this && (event->type()==QEvent::Leave))
|
||||
{
|
||||
QString styleSheet = "background-color:#454545; border-top: 1px solid #454545;border-bottom: 1px solid #454545;";
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
up->setHidden(true);
|
||||
down->setHidden(true);
|
||||
options->setHidden(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(object==this && (event->type()==QEvent::MouseButtonRelease))
|
||||
{
|
||||
QString styleSheet = "background-color:#2E2E2E; border-top: 1px solid #1F1F1F;border-bottom: 1px solid #636363; padding-top:1px; padding-bottom:1px;";
|
||||
setStyleSheet(styleSheet);
|
||||
emit(selected(name,path));
|
||||
isSelected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
void YACReaderLibraryItemWidget::deselect()
|
||||
{
|
||||
QString styleSheet = "background-color:transparent;";
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
QPixmap iconPixmap(":/images/libraryIcon.png");
|
||||
icon->setPixmap(iconPixmap);
|
||||
|
||||
/*up->setHidden(true);
|
||||
down->setHidden(true);*/
|
||||
options->setHidden(true);
|
||||
|
||||
isSelected = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void YACReaderLibraryItemWidget::select()
|
||||
{
|
||||
QString styleSheet = "color: white; background-color:#BBBBBB; font-weight:bold;";
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
options->setHidden(false);
|
||||
|
||||
QPixmap iconPixmap(":/images/libraryIconSelected.png");
|
||||
icon->setPixmap(iconPixmap);
|
||||
|
||||
isSelected = true;
|
||||
}
|
42
custom_widgets/yacreader_library_item_widget.h
Normal file
42
custom_widgets/yacreader_library_item_widget.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef YACREADER_LIBRARY_ITEM_WIDGET_H
|
||||
#define YACREADER_LIBRARY_ITEM_WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLabel;
|
||||
class QToolButton;
|
||||
class QMouseEvent;
|
||||
class QEvent;
|
||||
|
||||
class YACReaderLibraryItemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
YACReaderLibraryItemWidget(QString name, QString path, QWidget *parent = 0);
|
||||
QString name;
|
||||
QString path;
|
||||
|
||||
signals:
|
||||
void selected(QString,QString);
|
||||
public slots:
|
||||
void showUpDownButtons(bool show);
|
||||
|
||||
//bool eventFilter(QObject *object, QEvent *event);
|
||||
void select();
|
||||
void deselect();
|
||||
|
||||
private:
|
||||
|
||||
QLabel * icon;
|
||||
QLabel * nameLabel;
|
||||
|
||||
QToolButton * options;
|
||||
QToolButton * up;
|
||||
QToolButton * down;
|
||||
|
||||
bool isSelected;
|
||||
|
||||
};
|
||||
|
||||
#endif // YACREADER_LIBRARY_ITEM_WIDGET_H
|
97
custom_widgets/yacreader_library_list_widget.cpp
Normal file
97
custom_widgets/yacreader_library_list_widget.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include "yacreader_library_list_widget.h"
|
||||
|
||||
#include "yacreader_library_item_widget.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
|
||||
YACReaderLibraryListWidget::YACReaderLibraryListWidget(QWidget *parent) :
|
||||
QWidget(parent),currentLibraryIndex(0)
|
||||
{
|
||||
QVBoxLayout * mainLayout = new QVBoxLayout;
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
this->setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void YACReaderLibraryListWidget::addItem(QString name, QString path)
|
||||
{
|
||||
QVBoxLayout * mainLayout = dynamic_cast<QVBoxLayout *>(layout());
|
||||
|
||||
YACReaderLibraryItemWidget * library = new YACReaderLibraryItemWidget(name,path,this);
|
||||
librariesList.append(library);
|
||||
|
||||
connect(library,SIGNAL(selected(QString,QString)),this,SIGNAL(librarySelected(QString,QString)));
|
||||
connect(library,SIGNAL(selected(QString,QString)),this,SLOT(updateLibraries(QString,QString)));
|
||||
|
||||
mainLayout->addWidget(library);
|
||||
|
||||
//first item added
|
||||
if(librariesList.count()==1)
|
||||
{
|
||||
library->select();
|
||||
emit currentIndexChanged(name);
|
||||
}
|
||||
}
|
||||
|
||||
QString YACReaderLibraryListWidget::currentText()
|
||||
{
|
||||
return librariesList.at(currentLibraryIndex)->name;
|
||||
}
|
||||
int YACReaderLibraryListWidget::findText(QString text)
|
||||
{
|
||||
for(int i=0;i<librariesList.count();i++)
|
||||
{
|
||||
if(librariesList.at(i)->name == text)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
void YACReaderLibraryListWidget::setCurrentIndex(int index)
|
||||
{
|
||||
if(index>=0 && index < librariesList.count())
|
||||
{
|
||||
librariesList.at(index)->select();
|
||||
currentLibraryIndex = index;
|
||||
deselectAllBut(index);
|
||||
}
|
||||
}
|
||||
|
||||
int YACReaderLibraryListWidget::currentIndex()
|
||||
{
|
||||
return currentLibraryIndex;
|
||||
}
|
||||
void YACReaderLibraryListWidget::removeItem(int index)
|
||||
{
|
||||
YACReaderLibraryItemWidget * itemWidget = librariesList.at(index);
|
||||
this->layout()->removeWidget(itemWidget);
|
||||
librariesList.removeAt(index);
|
||||
if(librariesList.count()>0)
|
||||
{
|
||||
setCurrentIndex(0);
|
||||
emit currentIndexChanged(librariesList.at(0)->name);
|
||||
}
|
||||
delete itemWidget;
|
||||
}
|
||||
|
||||
void YACReaderLibraryListWidget::mousePressEvent ( QMouseEvent * event )
|
||||
{
|
||||
if(librariesList.count()>0)
|
||||
{
|
||||
int h = librariesList.at(0)->height();
|
||||
int item = event->pos().y() / h;
|
||||
//deselectAllBut(item);
|
||||
setCurrentIndex(item);
|
||||
emit currentIndexChanged(librariesList.at(item)->name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void YACReaderLibraryListWidget::deselectAllBut(int index)
|
||||
{
|
||||
for(int i=0;i<librariesList.count();i++)
|
||||
{
|
||||
if(i!=index)
|
||||
librariesList.at(i)->deselect();
|
||||
}
|
||||
}
|
35
custom_widgets/yacreader_library_list_widget.h
Normal file
35
custom_widgets/yacreader_library_list_widget.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef YACREADER_LIBRARY_LIST_WIDGET_H
|
||||
#define YACREADER_LIBRARY_LIST_WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class YACReaderLibraryItemWidget;
|
||||
class QMouseEvent;
|
||||
|
||||
class YACReaderLibraryListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderLibraryListWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void currentIndexChanged(QString text);
|
||||
|
||||
public slots:
|
||||
QString currentText();
|
||||
int findText(QString text);
|
||||
void setCurrentIndex(int index);
|
||||
void addItem(QString name, QString path);
|
||||
int currentIndex();
|
||||
void removeItem(int index);
|
||||
protected:
|
||||
void mousePressEvent ( QMouseEvent * event );
|
||||
private:
|
||||
int currentLibraryIndex;
|
||||
QList < YACReaderLibraryItemWidget* > librariesList;
|
||||
void deselectAllBut(int index);
|
||||
|
||||
};
|
||||
|
||||
#endif // YACREADER_LIBRARY_LIST_WIDGET_H
|
||||
|
@ -12,10 +12,13 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent) :
|
||||
|
||||
void YACReaderSideBar::paintEvent(QPaintEvent * event)
|
||||
{
|
||||
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
QPainter painter(this);
|
||||
|
||||
|
||||
QLinearGradient lG(0,0,0,height());
|
||||
|
||||
lG.setColorAt(0,QColor("#E8ECF1"));
|
||||
lG.setColorAt(1,QColor("#D1D8E0"));
|
||||
|
||||
@ -24,6 +27,8 @@ void YACReaderSideBar::paintEvent(QPaintEvent * event)
|
||||
QWidget::paintEvent(event);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//QPixmap shadow(":/images/side_bar/shadow.png");
|
||||
//painter.drawPixmap(width()-shadow.width(),0,shadow.width(),height(),shadow);
|
||||
|
||||
|
Reference in New Issue
Block a user