UBNavigatorPalette.cpp 4.7 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
 * the Free Software Foundation, either version 3 of the License, or
 * (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 16 17 18
#include "UBNavigatorPalette.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"

19 20
#include "core/memcheck.h"

Claudio Valerio's avatar
Claudio Valerio committed
21 22 23 24 25
/**
 * \brief Constructor
 * @param parent as the parent widget
 * @param name as the object name
 */
26 27
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name):
    UBDockPalette(eUBDockPaletteType_NAVIGATOR, parent, name)
Claudio Valerio's avatar
Claudio Valerio committed
28 29
	, mNavigator(NULL)
	, mLayout(NULL)
30 31 32
    , mHLayout(NULL)
    , mPageNbr(NULL)
    , mClock(NULL)
Claudio Valerio's avatar
Claudio Valerio committed
33 34 35
{
    setOrientation(eUBDockOrientation_Left);
    setMaximumWidth(300);
36 37
    //mCollapsedIcon = QPixmap(":images/pages_open.png");
    //mIcon = QPixmap(":images/pages_close.png");
38 39
    resize(UBSettings::settings()->navigPaletteWidth->get().toInt(), height());
    mLastWidth = 300;
Claudio Valerio's avatar
Claudio Valerio committed
40 41 42

    // Build the gui
    mLayout = new QVBoxLayout(this);
43
    mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin());
Claudio Valerio's avatar
Claudio Valerio committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    setLayout(mLayout);

    mNavigator = new UBDocumentNavigator(this);
    mNavigator->setStyleSheet(QString("background-color : transparent;"));
    mLayout->addWidget(mNavigator, 1);

    mHLayout = new QHBoxLayout();
    mLayout->addLayout(mHLayout, 0);

    mPageNbr = new QLabel(this);
    mClock = new QLabel(this);
    mHLayout->addWidget(mPageNbr);
    mHLayout->addWidget(mClock);

    // Configure the page number indicator
    mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
    setPageNumber(0, 0);
    mPageNbr->setAlignment(Qt::AlignHCenter);

    // Configure the clock
    mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
    mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
    mClock->setAlignment(Qt::AlignHCenter);

    //strip seconds
    mTimeFormat = mTimeFormat.remove(":ss");
    mTimeFormat = mTimeFormat.remove(":s");
    mTimerID = startTimer(1000);

    connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage()));  
}

/**
 * \brief Destructor
 */
UBNavigatorPalette::~UBNavigatorPalette()
{
    killTimer(mTimerID);

    if(NULL != mClock)
    {
        delete mClock;
        mClock = NULL;
    }
    if(NULL != mPageNbr)
    {
        delete mPageNbr;
        mPageNbr = NULL;
    }
    if(NULL != mHLayout)
    {
        delete mHLayout;
        mHLayout = NULL;
    }
    if(NULL != mLayout)
    {
	delete mLayout;
	mLayout = NULL;
    }
    if(NULL != mNavigator)
    {
	delete mNavigator;
	mNavigator = NULL;
    }
}

/**
 * \brief Set the current document in the navigator
 * @param document as the given document
 */
void UBNavigatorPalette::setDocument(UBDocumentProxy *document)
{
    if(mNavigator->currentDoc() != document)
    {
	mNavigator->setDocument(document);
    }
}

/**
 * \brief Change the current page
 */
void UBNavigatorPalette::changeCurrentPage()
{
    //	Get the index of the page to display
    int iPage = mNavigator->selectedPageNumber();
    if(NO_PAGESELECTED != iPage)
    {
	// Display the selected page
	UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage);
    }
}

/**
 * \brief Refresh the thumbnails widget
 */
void UBNavigatorPalette::refresh()
{
    mNavigator->setDocument(UBApplication::boardController->activeDocument());
}

/**
 * \brief Handle the resize event
 * @param event as the resize event
 */
void UBNavigatorPalette::resizeEvent(QResizeEvent *event)
{
    UBDockPalette::resizeEvent(event);
    if(NULL != mNavigator)
    {
        mNavigator->setMinimumHeight(height() - 2*border());
    }
155
    UBSettings::settings()->navigPaletteWidth->set(width());
Claudio Valerio's avatar
Claudio Valerio committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
}

void UBNavigatorPalette::timerEvent(QTimerEvent *event)
{
    Q_UNUSED(event);
    updateTime();
}

void UBNavigatorPalette::updateTime()
{
    if (mClock)
    {
        mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
    }
}

void UBNavigatorPalette::setPageNumber(int current, int total)
{
    mPageNbr->setText(QString("%1 / %2").arg(current).arg(total));
}