UBLibNavigatorWidget.cpp 6.07 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3
/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5 6 7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Claudio Valerio's avatar
Claudio Valerio committed
15
#include "UBLibNavigatorWidget.h"
16
#include "UBLibWidget.h"
Claudio Valerio's avatar
Claudio Valerio committed
17

shibakaneki's avatar
shibakaneki committed
18
#include "core/UBApplication.h"
19

20 21
#include "globals/UBGlobals.h"

22 23
#include "core/memcheck.h"

Claudio Valerio's avatar
Claudio Valerio committed
24 25 26 27 28 29 30 31 32 33
static int lowBoundForSlider = 40;
static int topBoundForSlider = 120;
static int tickIntervalForSlider = 10;

/**
 * \brief Constructor
 * @param parent as the parent widget
 * @param name as the object name
 */
UBLibNavigatorWidget::UBLibNavigatorWidget(QWidget *parent, const char *name):QWidget(parent)
34 35 36 37
  , mLayout(NULL)
  , mLibWidget(NULL)
  , mSlider(NULL)
  , mSliderWidthSetting(NULL)
Claudio Valerio's avatar
Claudio Valerio committed
38 39
{
    setObjectName(name);
shibakaneki's avatar
shibakaneki committed
40

41
    SET_STYLE_SHEET();
shibakaneki's avatar
shibakaneki committed
42

Claudio Valerio's avatar
Claudio Valerio committed
43 44
    setAcceptDrops(true);

45
    UBLibWidget* libWidget = dynamic_cast<UBLibWidget*>(parentWidget());
Claudio Valerio's avatar
Claudio Valerio committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    mLayout = new QVBoxLayout(this);
    setLayout(mLayout);

    mLibWidget = new UBLibraryWidget(this);
    mLayout->addWidget(mLibWidget, 1);

    mSlider = new QSlider(Qt::Horizontal, this);
    mSlider->setMinimumHeight(20);
    mSlider->setRange(lowBoundForSlider, topBoundForSlider);
    mSliderWidthSetting = new UBSetting(UBSettings::settings(), "Library", "LibWidgetWidth", topBoundForSlider);
    int defaultWidth = mSliderWidthSetting->get().toInt();
    mSlider->setValue(defaultWidth);
    mSlider->setTickInterval(tickIntervalForSlider);
    mLayout->addWidget(mSlider, 0);

    connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), this, SLOT(onNavigbarUpate(UBLibElement*)));
62 63
    connect(this, SIGNAL(updateNavigBar(UBChainedLibElement*)), libWidget, SLOT(onUpdateNavigBar(UBChainedLibElement*)));
    mLibWidget->updateThumbnailsSize(defaultWidth);
Claudio Valerio's avatar
Claudio Valerio committed
64

65

66
    connect(mLibWidget, SIGNAL(propertiesRequested(UBLibElement*)), this, SLOT(onPropertiesRequested(UBLibElement*)));
67
    connect(mLibWidget, SIGNAL(displaySearchEngine(UBLibElement*)), this, SLOT(onDisplaySearchEngine(UBLibElement*)));
68 69 70
    connect(mSlider,SIGNAL(valueChanged(int)),this,SLOT(updateThumbnailsSize(int)));
    connect(libWidget->pathViewer(), SIGNAL(mouseClick(UBChainedLibElement*)), this, SLOT(onPathItemClicked(UBChainedLibElement*)));
    connect(libWidget->pathViewer(), SIGNAL(elementsDropped(QList<QString>,UBLibElement*)), mLibWidget, SLOT(onElementsDropped(QList<QString>,UBLibElement*)));
71 72 73 74 75 76
    connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), libWidget->actionBar(), SLOT(onNavigbarUpdate(UBLibElement*)));
    connect(mLibWidget, SIGNAL(itemsSelected(QList<UBLibElement*>, bool)), libWidget->actionBar(), SLOT(onSelectionChanged(QList<UBLibElement*>, bool)));
    connect(libWidget->actionBar(), SIGNAL(deleteDone()), mLibWidget, SLOT(onRefreshCurrentFolder()));
    connect(mLibWidget, SIGNAL(favoritesEntered(bool)), libWidget->actionBar(), SLOT(onFavoritesEntered(bool)));
    connect(libWidget->actionBar(), SIGNAL(searchElement(QString)), mLibWidget, SLOT(onSearchElement(QString)));
    connect(libWidget->actionBar(), SIGNAL(newFolderToCreate()), mLibWidget, SLOT(onNewFolderToCreate()));
77
    connect(mLibWidget, SIGNAL(itemClicked()),libWidget->actionBar(), SLOT(onItemChanged()));
78
    connect(libWidget->pathViewer(), SIGNAL(mouseClick(UBChainedLibElement*)),libWidget->actionBar(), SLOT(onItemChanged()));
Claudio Valerio's avatar
Claudio Valerio committed
79 80 81 82 83 84 85 86
    mLibWidget->init();
}

/**
 * \brief Destructor
 */
UBLibNavigatorWidget::~UBLibNavigatorWidget()
{
87
    if(NULL != mLibWidget)
Claudio Valerio's avatar
Claudio Valerio committed
88
    {
89 90
        delete mLibWidget;
        mLibWidget = NULL;
Claudio Valerio's avatar
Claudio Valerio committed
91 92 93 94 95 96 97 98 99 100 101
    }
    if(NULL != mSlider)
    {
        delete mSlider;
        mSlider = NULL;
    }
    if(NULL != mSliderWidthSetting)
    {
        delete mSliderWidthSetting;
        mSliderWidthSetting = NULL;
    }
102 103 104 105 106
    if(NULL != mLayout)
    {
        delete mLayout;
        mLayout = NULL;
    }
Claudio Valerio's avatar
Claudio Valerio committed
107 108
}

shibakaneki's avatar
shibakaneki committed
109 110 111
void UBLibNavigatorWidget::dropMe(const QMimeData *_data)
{
    // Forward the mime data to the library widget
112
    Q_UNUSED(_data);
shibakaneki's avatar
shibakaneki committed
113 114
}

Claudio Valerio's avatar
Claudio Valerio committed
115 116 117 118 119 120
/**
 * \brief Update the navigation bar
 * @param pElem as the current element
 */
void UBLibNavigatorWidget::onNavigbarUpate(UBLibElement *pElem)
{
121 122
    Q_UNUSED(pElem);
    emit updateNavigBar(mLibWidget->chainedElements);
Claudio Valerio's avatar
Claudio Valerio committed
123 124 125 126 127 128 129 130
}

/**
 * \brief Handle the click event on an item
 * @param elem as the clicked element
 */
void UBLibNavigatorWidget::onPathItemClicked(UBChainedLibElement *elem)
{
131 132 133 134 135 136 137 138
	if (!this->libraryWidget()->isLoadingLibraryItems())
	{
		// If this element has some subelement, remove them
		removeNextChainedElements(elem);

		// The refresh the view
		mLibWidget->setCurrentElemsAndRefresh(elem);
	}
Claudio Valerio's avatar
Claudio Valerio committed
139 140 141 142 143 144 145 146 147 148 149 150
}

/**
 * \brief Remove the next chained elements
 * @param fromElem as the current elem
 */
void UBLibNavigatorWidget::removeNextChainedElements(UBChainedLibElement *fromElem)
{
    if(NULL != fromElem)
    {
        if(NULL != fromElem->nextElement())
        {
151 152 153
            //removeNextChainedElements(fromElem->nextElement());
            //delete fromElem->nextElement()->element();
            //delete fromElem->nextElement();
Claudio Valerio's avatar
Claudio Valerio committed
154 155 156 157 158 159 160 161
            delete fromElem->nextElement();
            fromElem->setNextElement(NULL);
        }
    }
}

/**
 * \brief Handles the properties requested event
162
 * @param elem as the related element
Claudio Valerio's avatar
Claudio Valerio committed
163 164 165 166 167 168
 */
void UBLibNavigatorWidget::onPropertiesRequested(UBLibElement *elem)
{
    emit propertiesRequested(elem);
}

169 170 171 172 173 174 175 176 177
/**
 * \brief Handles the display search engine requested event
 * @param elem as the related element
 */
void UBLibNavigatorWidget::onDisplaySearchEngine(UBLibElement *elem)
{
    emit displaySearchEngine(elem);
}

Claudio Valerio's avatar
Claudio Valerio committed
178 179 180 181 182 183 184 185 186
/**
 * \brief Update the thumbnails size
 * @param newSize as the given thumbnails size
 */
void UBLibNavigatorWidget::updateThumbnailsSize(int newSize)
{
    mSliderWidthSetting->set(newSize);
    mLibWidget->updateThumbnailsSize(newSize);
}