From 6d9d20bb5d264b54c4704656cd5725e51bd4f358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 18 Jun 2013 11:17:47 +0200 Subject: [PATCH] cambiado el comportamiento de librarylistwidget --- YACReaderLibrary/library_window.cpp | 2 ++ .../yacreader_library_list_widget.cpp | 30 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index afec28b0..a9ea695a 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1142,6 +1142,8 @@ void LibraryWindow::loadLibraries() { disableAllActions(); } + else + selectedLibrary->setCurrentIndex(0); } void LibraryWindow::saveLibraries() diff --git a/custom_widgets/yacreader_library_list_widget.cpp b/custom_widgets/yacreader_library_list_widget.cpp index 8aa233cc..b8f70c44 100644 --- a/custom_widgets/yacreader_library_list_widget.cpp +++ b/custom_widgets/yacreader_library_list_widget.cpp @@ -4,9 +4,10 @@ #include #include #include +#include "qnaturalsorting.h" YACReaderLibraryListWidget::YACReaderLibraryListWidget(QWidget *parent) : - QWidget(parent),currentLibraryIndex(0) + QWidget(parent),currentLibraryIndex(-1) { QVBoxLayout * mainLayout = new QVBoxLayout; mainLayout->setSpacing(0); @@ -21,19 +22,17 @@ void YACReaderLibraryListWidget::addItem(QString name, QString path) YACReaderLibraryItemWidget * library = new YACReaderLibraryItemWidget(name,path,this); connect(library,SIGNAL(showOptions()),this,SLOT(showContextMenu())); - librariesList.append(library); + QList::iterator itr; + int i = 0; + for(itr = librariesList.begin(); itr!=librariesList.end() && !naturalSortLessThanCI(name,(*itr)->name);itr++) + i++; - connect(library,SIGNAL(selected(QString,QString)),this,SIGNAL(librarySelected(QString,QString))); + librariesList.insert(itr,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); - } + mainLayout->insertWidget(i,library); } QString YACReaderLibraryListWidget::currentText() @@ -55,6 +54,7 @@ void YACReaderLibraryListWidget::setCurrentIndex(int index) librariesList.at(index)->select(); currentLibraryIndex = index; deselectAllBut(index); + emit currentIndexChanged(librariesList.at(currentLibraryIndex)->name); } } @@ -70,7 +70,6 @@ void YACReaderLibraryListWidget::removeItem(int index) if(librariesList.count()>0) { setCurrentIndex(0); - emit currentIndexChanged(librariesList.at(0)->name); } delete itemWidget; } @@ -81,9 +80,10 @@ void YACReaderLibraryListWidget::mousePressEvent ( QMouseEvent * event ) { int h = librariesList.at(0)->height(); int item = event->pos().y() / h; - //deselectAllBut(item); - setCurrentIndex(item); - emit currentIndexChanged(librariesList.at(item)->name); + if(item!=currentLibraryIndex) + { + setCurrentIndex(item); + } } }