UBRightPalette.cpp 3.39 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
 * (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/>.
 */
15 16 17
#include "core/UBApplication.h"
#include "board/UBBoardController.h"

18 19
#include "UBRightPalette.h"

20 21
#include "core/memcheck.h"

22 23 24
/**
 * \brief The constructor
 */
25 26
UBRightPalette::UBRightPalette(QWidget *parent, const char *name):
    UBDockPalette(eUBDockPaletteType_RIGHT, parent)
27 28 29
{
    setObjectName(name);
    setOrientation(eUBDockOrientation_Right);
Ivan Ilin's avatar
Ivan Ilin committed
30
    mCollapseWidth = 150;
Claudio Valerio's avatar
Claudio Valerio committed
31 32 33 34 35 36 37 38 39 40
    bool isCollapsed = false;
    if(mCurrentMode == eUBDockPaletteWidget_BOARD){
    	mLastWidth = UBSettings::settings()->rightLibPaletteBoardModeWidth->get().toInt();
    	isCollapsed = UBSettings::settings()->rightLibPaletteBoardModeIsCollapsed->get().toBool();
    }
    else{
    	mLastWidth = UBSettings::settings()->rightLibPaletteDesktopModeWidth->get().toInt();
    	isCollapsed = UBSettings::settings()->rightLibPaletteDesktopModeIsCollapsed->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 51 52
UBRightPalette::~UBRightPalette()
{
}

53 54 55 56
/**
 * \brief Handle the mouse move event
 * @event as the mouse move event
 */
57 58 59 60 61 62 63 64
void UBRightPalette::mouseMoveEvent(QMouseEvent *event)
{
    if(mCanResize)
    {
        UBDockPalette::mouseMoveEvent(event);
    }
}

65 66 67 68
/**
 * \brief Handle the resize event
 * @param event as the resize event
 */
69 70
void UBRightPalette::resizeEvent(QResizeEvent *event)
{
Claudio Valerio's avatar
Claudio Valerio committed
71
	int newWidth = width();
Claudio Valerio's avatar
Claudio Valerio committed
72 73 74 75 76 77 78 79 80 81 82
	if(mCurrentMode == eUBDockPaletteWidget_BOARD){
		if(newWidth > mCollapseWidth)
			UBSettings::settings()->rightLibPaletteBoardModeWidth->set(newWidth);
		UBSettings::settings()->rightLibPaletteBoardModeIsCollapsed->set(newWidth == 0);
	}
	else{
		if(newWidth > mCollapseWidth)
			UBSettings::settings()->rightLibPaletteDesktopModeWidth->set(newWidth);
		UBSettings::settings()->rightLibPaletteDesktopModeIsCollapsed->set(newWidth == 0);
	}
	UBDockPalette::resizeEvent(event);
83 84 85
    emit resized();
}

86 87 88
/**
 * \brief Update the maximum width
 */
89 90
void UBRightPalette::updateMaxWidth()
{
91
    setMaximumWidth((int)(parentWidget()->width() * 0.45));
92 93 94
    setMaximumHeight(parentWidget()->height());
    setMinimumHeight(parentWidget()->height());
}
Claudio Valerio's avatar
Claudio Valerio committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

bool UBRightPalette::switchMode(eUBDockPaletteWidgetMode mode)
{
	int newModeWidth;
	if(mode == eUBDockPaletteWidget_BOARD){
		mLastWidth = UBSettings::settings()->rightLibPaletteBoardModeWidth->get().toInt();
		newModeWidth = mLastWidth;
		if(UBSettings::settings()->rightLibPaletteBoardModeIsCollapsed->get().toBool())
			newModeWidth = 0;
	}
	else{
		mLastWidth = UBSettings::settings()->rightLibPaletteDesktopModeWidth->get().toInt();
		newModeWidth = mLastWidth;
		if(UBSettings::settings()->rightLibPaletteDesktopModeIsCollapsed->get().toBool())
			newModeWidth = 0;
	}
	resize(newModeWidth,height());
	return UBDockPalette::switchMode(mode);
}