UBLeftPalette.cpp 3.74 KB
Newer Older
1
/*
Craig Watson's avatar
Craig Watson committed
2 3
 * Copyright (C) 2015-2016 Département de l'Instruction Publique (DIP-SEM)
 *
Claudio Valerio's avatar
Claudio Valerio committed
4
 * Copyright (C) 2013 Open Education Foundation
5
 *
Claudio Valerio's avatar
Claudio Valerio committed
6 7
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8
 *
Claudio Valerio's avatar
Claudio Valerio committed
9 10 11
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
14 15 16 17
 * with a specific linking exception for the OpenSSL project's
 * "OpenSSL" library (or with modified versions of it that use the
 * same license as the "OpenSSL" library).
 *
Claudio Valerio's avatar
Claudio Valerio committed
18
 * OpenBoard is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Claudio Valerio's avatar
Claudio Valerio committed
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Claudio Valerio's avatar
Claudio Valerio committed
21
 * GNU General Public License for more details.
22
 *
Claudio Valerio's avatar
Claudio Valerio committed
23
 * You should have received a copy of the GNU General Public License
Claudio Valerio's avatar
Claudio Valerio committed
24
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
25
 */
26 27


Claudio Valerio's avatar
Claudio Valerio committed
28

Claudio Valerio's avatar
Claudio Valerio committed
29

30
#include "UBLeftPalette.h"
31
#include "core/UBSettings.h"
32

33 34
#include "core/memcheck.h"

35 36 37
/**
 * \brief The constructor
 */
38 39
UBLeftPalette::UBLeftPalette(QWidget *parent, const char *name):
    UBDockPalette(eUBDockPaletteType_LEFT, parent)
40
{
41 42 43
    setObjectName(name);
    setOrientation(eUBDockOrientation_Left);
    mCollapseWidth = 150;
44

Claudio Valerio's avatar
Claudio Valerio committed
45 46
    bool isCollapsed = false;
    if(mCurrentMode == eUBDockPaletteWidget_BOARD){
47 48
        mLastWidth = UBSettings::settings()->leftLibPaletteBoardModeWidth->get().toInt();
        isCollapsed = UBSettings::settings()->leftLibPaletteBoardModeIsCollapsed->get().toBool();
Claudio Valerio's avatar
Claudio Valerio committed
49 50
    }
    else{
51 52
        mLastWidth = UBSettings::settings()->leftLibPaletteDesktopModeWidth->get().toInt();
        isCollapsed = UBSettings::settings()->leftLibPaletteDesktopModeIsCollapsed->get().toBool();
Claudio Valerio's avatar
Claudio Valerio committed
53 54 55
    }

    if(isCollapsed)
56
        resize(0,parentWidget()->height());
Claudio Valerio's avatar
Claudio Valerio committed
57
    else
58
        resize(mLastWidth, parentWidget()->height());
59 60
}

61 62 63
/**
 * \brief The destructor
 */
64 65
UBLeftPalette::~UBLeftPalette()
{
66

67 68
}

Claudio Valerio's avatar
Claudio Valerio committed
69 70 71

void UBLeftPalette::onDocumentSet(UBDocumentProxy* documentProxy)
{
Claudio Valerio's avatar
Claudio Valerio committed
72
    Q_UNUSED(documentProxy)
73 74
    // the tab zero is forced
    mLastOpenedTabForMode.insert(eUBDockPaletteWidget_BOARD, 0);
Claudio Valerio's avatar
Claudio Valerio committed
75 76
}

77 78 79
/**
 * \brief Update the maximum width
 */
80 81
void UBLeftPalette::updateMaxWidth()
{
82
    setMaximumWidth((int)(parentWidget()->width() * 0.45));
83 84
}

85 86 87 88
/**
 * \brief Handle the resize event
 * @param event as the resize event
 */
89 90
void UBLeftPalette::resizeEvent(QResizeEvent *event)
{
91 92 93 94 95 96 97 98 99 100 101
    int newWidth = width();
    if(mCurrentMode == eUBDockPaletteWidget_BOARD){
        if(newWidth > mCollapseWidth)
            UBSettings::settings()->leftLibPaletteBoardModeWidth->set(newWidth);
        UBSettings::settings()->leftLibPaletteBoardModeIsCollapsed->set(newWidth == 0);
    }
    else{
        if(newWidth > mCollapseWidth)
            UBSettings::settings()->leftLibPaletteDesktopModeWidth->set(newWidth);
        UBSettings::settings()->leftLibPaletteDesktopModeIsCollapsed->set(newWidth == 0);
    }
102 103
    UBDockPalette::resizeEvent(event);
}
Claudio Valerio's avatar
Claudio Valerio committed
104 105 106 107


bool UBLeftPalette::switchMode(eUBDockPaletteWidgetMode mode)
{
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    int newModeWidth;
    if(mode == eUBDockPaletteWidget_BOARD){
        mLastWidth = UBSettings::settings()->leftLibPaletteBoardModeWidth->get().toInt();
        newModeWidth = mLastWidth;
        if(UBSettings::settings()->leftLibPaletteBoardModeIsCollapsed->get().toBool())
            newModeWidth = 0;
    }
    else{
        mLastWidth = UBSettings::settings()->leftLibPaletteDesktopModeWidth->get().toInt();
        newModeWidth = mLastWidth;
        if(UBSettings::settings()->leftLibPaletteDesktopModeIsCollapsed->get().toBool())
            newModeWidth = 0;
    }
    resize(newModeWidth,height());
    return UBDockPalette::switchMode(mode);
Claudio Valerio's avatar
Claudio Valerio committed
123
}