14 #include <QVBoxLayout> 23 mShiftSplitterLeft(NULL),
24 mShiftSplitterRight(NULL),
28 QVBoxLayout* layout =
new QVBoxLayout(
this);
30 layout->setSpacing(0);
32 mSplitter =
new QSplitter(Qt::Horizontal);
33 connect(mSplitter, &QSplitter::splitterMoved,
this, &ControllableSplitter::onSplitterMoved);
35 layout->addWidget(mSplitter, 1);
37 mSplitterRatio = this->getSplitterRatioOption().
readValue(QString::number(0.5)).toDouble();
40 QTimer::singleShot(0,
this, SLOT(initializeSettings()));
45 this->getSplitterRatioOption().
writeValue(QString::number(mSplitterRatio));
46 this->getShiftStateOption().
writeValue(QString::number(this->getShiftState()));
62 mSplitter->insertWidget(0, widget);
67 mSplitter->insertWidget(1, widget);
70 void ControllableSplitter::initializeSettings()
72 this->setShiftState(this->getShiftStateOption().readValue(
"0").toInt());
73 this->onSplitterMoved();
78 if (!mShiftSplitterLeft)
80 QAction* action =
new QAction(QIcon(
":/icons/open_icon_library/arrow-left-3.png"),
81 QString(
"Show %1").arg(mRightName),
this);
82 action->setToolTip(QString(
"Show more %1").arg(mRightName));
83 action->setStatusTip(action->toolTip());
84 connect(action, &QAction::triggered,
this, &ControllableSplitter::onMoveSplitterLeft);
85 mShiftSplitterLeft = action;
86 this->enableActions();
88 return mShiftSplitterLeft;
93 if (!mShiftSplitterRight)
95 QAction* action =
new QAction(QIcon(
":/icons/open_icon_library/arrow-right-3.png"),
96 QString(
"Show %1").arg(mLeftName),
this);
97 action->setToolTip(QString(
"Show more %1").arg(mLeftName));
98 action->setStatusTip(action->toolTip());
99 connect(action, &QAction::triggered,
this, &ControllableSplitter::onMoveSplitterRight);
100 mShiftSplitterRight = action;
101 this->enableActions();
103 return mShiftSplitterRight;
106 void ControllableSplitter::onMoveSplitterLeft()
108 this->shiftSplitter(-1);
111 void ControllableSplitter::onMoveSplitterRight()
113 this->shiftSplitter(+1);
116 void ControllableSplitter::onSplitterMoved()
118 QList<int> sizes = mSplitter->sizes();
119 if (this->splitterShowsBoth())
120 mSplitterRatio = double(sizes[0]) /double(sizes[0]+sizes[1]);
122 this->enableActions();
125 void ControllableSplitter::enableActions()
127 if (mShiftSplitterLeft)
128 mShiftSplitterLeft->setEnabled(this->getShiftState()>=0);
129 if (mShiftSplitterRight)
130 mShiftSplitterRight->setEnabled(this->getShiftState()<=0);
133 bool ControllableSplitter::splitterShowsBoth()
const 135 QList<int> sizes = mSplitter->sizes();
136 return (( sizes.size()==2 )&&( sizes[0]!=0 )&&( sizes[1]!=0 ));
139 int ControllableSplitter::getShiftState()
const 141 QList<int> sizes = mSplitter->sizes();
156 void ControllableSplitter::setShiftState(
int shiftState)
158 QList<int> sizes = mSplitter->sizes();
165 else if (shiftState>0)
172 int sizesum = sizes[0]+sizes[1];
175 sizes[0] = mSplitterRatio * sizesum;
176 sizes[1] = (1.0-mSplitterRatio) * sizesum;
179 mSplitter->setSizes(sizes);
181 this->onSplitterMoved();
184 void ControllableSplitter::shiftSplitter(
int shift)
188 int shiftState = this->getShiftState();
190 this->setShiftState(shiftState);
void addLeftWidget(QWidget *widget, QString name)
QDomElement getElement()
return the current element
Helper class for storing one string value in an xml document.
void writeValue(const QString &val)
ControllableSplitter(XmlOptionFile options, QWidget *parent)
void addRightWidget(QWidget *widget, QString name)
Helper class for xml files used to store ssc/cx data.
QAction * getMoveLeftAction()
QString readValue(const QString &defval) const
QAction * getMoveRightAction()
Namespace for all CustusX production code.