colorized empty label widget and fixed label info on insert

This commit is contained in:
Luis Ángel San Martín
2014-11-21 22:08:46 +01:00
parent dcc4745812
commit 12604854ea
9 changed files with 99 additions and 32 deletions

View File

@ -55,7 +55,7 @@ AddLabelDialog::AddLabelDialog(QWidget *parent) :
YACReader::LabelColors AddLabelDialog::selectedColor() YACReader::LabelColors AddLabelDialog::selectedColor()
{ {
return YACReader::LabelColors(list->currentRow()); return YACReader::LabelColors(list->currentRow()+1);
} }
QString AddLabelDialog::name() QString AddLabelDialog::name()

View File

@ -73,6 +73,12 @@ QVariant ReadingListModel::data(const QModelIndex &index, int role) const
return QVariant(ReadingListModel::Separator); return QVariant(ReadingListModel::Separator);
} }
if (role == ReadingListModel::LabelColorRole && typeid(*item) == typeid(LabelItem) )
{
LabelItem * labelItem = static_cast<LabelItem*>(item);
return QVariant(labelItem->colorid());
}
if (role == ReadingListModel::IDRole) if (role == ReadingListModel::IDRole)
return item->getId(); return item->getId();

View File

@ -52,7 +52,8 @@ public:
enum Roles { enum Roles {
TypeListsRole = Qt::UserRole + 1, TypeListsRole = Qt::UserRole + 1,
IDRole IDRole,
LabelColorRole
}; };
enum TypeList { enum TypeList {

View File

@ -36,10 +36,10 @@ EmptyLabelWidget::EmptyLabelWidget(QWidget *parent) :
void EmptyLabelWidget::setColor(YACReader::LabelColors color) void EmptyLabelWidget::setColor(YACReader::LabelColors color)
{ {
//TODO tint the widget depending on color QPixmap p(":/images/empty_label.png");
//backgroundColor = "#FF0000"; QImage img = p.toImage().convertToFormat(QImage::Format_ARGB32);
YACReader::colorize(img,QColor(YACReader::labelColorToRGBString(color)));
//repaint(); iconLabel->setPixmap(QPixmap::fromImage(img));
} }
void EmptyLabelWidget::paintEvent(QPaintEvent * event) void EmptyLabelWidget::paintEvent(QPaintEvent * event)

View File

@ -80,32 +80,31 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex
void YACReaderNavigationController::loadListInfo(const QModelIndex &modelIndex) void YACReaderNavigationController::loadListInfo(const QModelIndex &modelIndex)
{ {
qulonglong id = modelIndex.data(ReadingListModel::IDRole).toULongLong();
switch(modelIndex.data(ReadingListModel::TypeListsRole).toInt()) switch(modelIndex.data(ReadingListModel::TypeListsRole).toInt())
{ {
case ReadingListModel::SpecialList: case ReadingListModel::SpecialList:
loadSpecialListInfo(id); loadSpecialListInfo(modelIndex);
break; break;
case ReadingListModel::Label: case ReadingListModel::Label:
loadLabelInfo(id); loadLabelInfo(modelIndex);
break; break;
case ReadingListModel::ReadingList: case ReadingListModel::ReadingList:
loadReadingListInfo(id); loadReadingListInfo(modelIndex);
break; break;
} }
} }
void YACReaderNavigationController::loadSpecialListInfo(const qulonglong id) void YACReaderNavigationController::loadSpecialListInfo(const QModelIndex &modelIndex)
{ {
} }
void YACReaderNavigationController::loadLabelInfo(const qulonglong id) void YACReaderNavigationController::loadLabelInfo(const QModelIndex &modelIndex)
{ {
//check comics in folder with id = folderId qulonglong id = modelIndex.data(ReadingListModel::IDRole).toULongLong();
//check comics in label with id = id
libraryWindow->comicsModel->setupLabelModelData(id,libraryWindow->foldersModel->getDatabase()); libraryWindow->comicsModel->setupLabelModelData(id,libraryWindow->foldersModel->getDatabase());
libraryWindow->comicsView->setModel(libraryWindow->comicsModel); libraryWindow->comicsView->setModel(libraryWindow->comicsModel);
@ -119,13 +118,13 @@ void YACReaderNavigationController::loadLabelInfo(const qulonglong id)
else{ else{
//showEmptyFolder //showEmptyFolder
//loadEmptyLabelInfo(); //there is no info in an empty label by now, TODO design something //loadEmptyLabelInfo(); //there is no info in an empty label by now, TODO design something
//TODO libraryWindow->emptyLabelWidget->setColor(YACReader::YRed); libraryWindow->emptyLabelWidget->setColor((YACReader::LabelColors)modelIndex.data(ReadingListModel::LabelColorRole).toInt());
libraryWindow->showEmptyLabelView(); libraryWindow->showEmptyLabelView();
libraryWindow->disableComicsActions(true); libraryWindow->disableComicsActions(true);
} }
} }
void YACReaderNavigationController::loadReadingListInfo(const qulonglong id) void YACReaderNavigationController::loadReadingListInfo(const QModelIndex &modelIndex)
{ {
} }

View File

@ -30,9 +30,9 @@ public slots:
void loadFolderInfo(const QModelIndex & modelIndex); void loadFolderInfo(const QModelIndex & modelIndex);
void loadListInfo(const QModelIndex & modelIndex); void loadListInfo(const QModelIndex & modelIndex);
void loadSpecialListInfo(const qulonglong id); void loadSpecialListInfo(const QModelIndex & modelIndex);
void loadLabelInfo(const qulonglong id); void loadLabelInfo(const QModelIndex & modelIndex);
void loadReadingListInfo(const qulonglong id); void loadReadingListInfo(const QModelIndex & modelIndex);
void loadPreviousStatus(); void loadPreviousStatus();

View File

@ -32,29 +32,29 @@ QAction * YACReader::createSeparator()
QString YACReader::colorToName(LabelColors colors) QString YACReader::colorToName(LabelColors colors)
{ {
switch(colors){ switch(colors){
case 0: case YRed:
return "red"; return "red";
case 1: case YOrange:
return "orange"; return "orange";
case 2: case YYellow:
return "yellow"; return "yellow";
case 3: case YGreen:
return "green"; return "green";
case 4: case YCyan:
return "cyan"; return "cyan";
case 5: case YBlue:
return "blue"; return "blue";
case 6: case YViolet:
return "violet"; return "violet";
case 7: case YPurple:
return "purple"; return "purple";
case 8: case YPink:
return "pink"; return "pink";
case 9: case YWhite:
return "white"; return "white";
case 10: case YLight:
return "light"; return "light";
case 11: case YDark:
return "dark"; return "dark";
} }
} }
@ -68,3 +68,62 @@ QIcon YACReader::noHighlightedIcon(const QString &path)
icon.addPixmap(p,QIcon::Selected); icon.addPixmap(p,QIcon::Selected);
return icon; return icon;
} }
void YACReader::colorize(QImage &img, QColor &col)
{
QRgb *data = (QRgb *)img.bits();
QRgb *end = data + img.width()*img.height();
int rcol = col.red(), gcol = col.green(), bcol = col.blue();
while(data != end) {
*data = qRgba(rcol,gcol,bcol,qAlpha(*data));
++data;
}
}
QString YACReader::labelColorToRGBString(LabelColors color)
{
switch (color) {
case YRed:
return "#FD777C";
case YOrange:
return "#FEBF34";
case YYellow:
return "#F5E934";
case YGreen:
return "#B6E525";
case YCyan:
return "#9FFFDD";
case YBlue:
return "#82C7FF";
case YViolet:
return "#8286FF";
case YPurple:
return "#E39FFF";
case YPink:
return "#FF9FDD";
#ifdef Q_OS_MAC
case YWhite: case YLight: case YDark:
return "#E3E3E3";
#else
case YWhite:
return "#FFFFFF";
case YLight:
return "#C8C8C8";
case YDark:
return "#ABABAB";
#endif
}
}

View File

@ -113,7 +113,7 @@ namespace YACReader
}; };
enum LabelColors{ enum LabelColors{
YRed = 0, YRed = 1,
YOrange, YOrange,
YYellow, YYellow,
YGreen, YGreen,
@ -132,6 +132,8 @@ void addSperator(QWidget * w);
QAction * createSeparator(); QAction * createSeparator();
QString colorToName(LabelColors colors); QString colorToName(LabelColors colors);
QIcon noHighlightedIcon(const QString & path); QIcon noHighlightedIcon(const QString & path);
void colorize(QImage &img, QColor &col);
QString labelColorToRGBString(LabelColors color);
} }
#endif #endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB