UBLeftPalette.cpp 3.01 KB
Newer Older
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
5 6 7 8 9 10 11 12 13 14 15
 * (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/>.
 */
#include "UBLeftPalette.h"
16
#include "core/UBSettings.h"
17

18 19
#include "core/memcheck.h"

20 21 22
/**
 * \brief The constructor
 */
23 24
UBLeftPalette::UBLeftPalette(QWidget *parent, const char *name):
    UBDockPalette(eUBDockPaletteType_LEFT, parent)
25
{
26 27 28
    setObjectName(name);
    setOrientation(eUBDockOrientation_Left);
    mCollapseWidth = 150;
29

Claudio Valerio's avatar
Claudio Valerio committed
30 31 32 33 34 35 36 37 38 39 40
    bool isCollapsed = false;
    if(mCurrentMode == eUBDockPaletteWidget_BOARD){
    	mLastWidth = UBSettings::settings()->leftLibPaletteBoardModeWidth->get().toInt();
    	isCollapsed = UBSettings::settings()->leftLibPaletteBoardModeIsCollapsed->get().toBool();
    }
    else{
    	mLastWidth = UBSettings::settings()->leftLibPaletteDesktopModeWidth->get().toInt();
    	isCollapsed = UBSettings::settings()->leftLibPaletteDesktopModeIsCollapsed->get().toBool();
    }

    if(isCollapsed)
Claudio Valerio's avatar
Claudio Valerio committed
41 42 43
    	resize(0,parentWidget()->height());
    else
    	resize(mLastWidth, parentWidget()->height());
44 45
}

46 47 48
/**
 * \brief The destructor
 */
49 50
UBLeftPalette::~UBLeftPalette()
{
51

52 53
}

54 55 56
/**
 * \brief Update the maximum width
 */
57 58
void UBLeftPalette::updateMaxWidth()
{
59
    setMaximumWidth((int)(parentWidget()->width() * 0.45));
60 61
}

62 63 64 65
/**
 * \brief Handle the resize event
 * @param event as the resize event
 */
66 67
void UBLeftPalette::resizeEvent(QResizeEvent *event)
{
Claudio Valerio's avatar
Claudio Valerio committed
68
	int newWidth = width();
Claudio Valerio's avatar
Claudio Valerio committed
69 70 71 72 73 74 75 76 77 78
	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);
	}
79 80
    UBDockPalette::resizeEvent(event);
}
Claudio Valerio's avatar
Claudio Valerio committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100


bool UBLeftPalette::switchMode(eUBDockPaletteWidgetMode mode)
{
	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);
}