35 #include <QVBoxLayout>
43 mShiftSplitterLeft(NULL),
44 mShiftSplitterRight(NULL),
48 QVBoxLayout* layout =
new QVBoxLayout(
this);
50 layout->setSpacing(0);
52 mSplitter =
new QSplitter(Qt::Horizontal);
53 connect(mSplitter, &QSplitter::splitterMoved,
this, &ControllableSplitter::onSplitterMoved);
55 layout->addWidget(mSplitter, 1);
57 mSplitterRatio = this->getSplitterRatioOption().
readValue(QString::number(0.5)).toDouble();
60 QTimer::singleShot(0,
this, SLOT(initializeSettings()));
65 this->getSplitterRatioOption().
writeValue(QString::number(mSplitterRatio));
66 this->getShiftStateOption().
writeValue(QString::number(this->getShiftState()));
74 XmlOptionItem ControllableSplitter::getShiftStateOption()
76 return XmlOptionItem(
"shift_state", mOptions.
getElement());
82 mSplitter->insertWidget(0, widget);
87 mSplitter->insertWidget(1, widget);
90 void ControllableSplitter::initializeSettings()
92 this->setShiftState(this->getShiftStateOption().readValue(
"0").toInt());
93 this->onSplitterMoved();
98 if (!mShiftSplitterLeft)
100 QAction* action =
new QAction(QIcon(
":/icons/open_icon_library/arrow-left-3.png"),
101 QString(
"Show %1").arg(mRightName),
this);
102 action->setToolTip(QString(
"Show more %1").arg(mRightName));
103 action->setStatusTip(action->toolTip());
104 connect(action, &QAction::triggered,
this, &ControllableSplitter::onMoveSplitterLeft);
105 mShiftSplitterLeft = action;
106 this->enableActions();
108 return mShiftSplitterLeft;
113 if (!mShiftSplitterRight)
115 QAction* action =
new QAction(QIcon(
":/icons/open_icon_library/arrow-right-3.png"),
116 QString(
"Show %1").arg(mLeftName),
this);
117 action->setToolTip(QString(
"Show more %1").arg(mLeftName));
118 action->setStatusTip(action->toolTip());
119 connect(action, &QAction::triggered,
this, &ControllableSplitter::onMoveSplitterRight);
120 mShiftSplitterRight = action;
121 this->enableActions();
123 return mShiftSplitterRight;
126 void ControllableSplitter::onMoveSplitterLeft()
128 this->shiftSplitter(-1);
131 void ControllableSplitter::onMoveSplitterRight()
133 this->shiftSplitter(+1);
136 void ControllableSplitter::onSplitterMoved()
138 QList<int> sizes = mSplitter->sizes();
139 if (this->splitterShowsBoth())
140 mSplitterRatio = double(sizes[0]) /double(sizes[0]+sizes[1]);
142 this->enableActions();
145 void ControllableSplitter::enableActions()
147 if (mShiftSplitterLeft)
148 mShiftSplitterLeft->setEnabled(this->getShiftState()>=0);
149 if (mShiftSplitterRight)
150 mShiftSplitterRight->setEnabled(this->getShiftState()<=0);
153 bool ControllableSplitter::splitterShowsBoth()
const
155 QList<int> sizes = mSplitter->sizes();
156 return (( sizes.size()==2 )&&( sizes[0]!=0 )&&( sizes[1]!=0 ));
159 int ControllableSplitter::getShiftState()
const
161 QList<int> sizes = mSplitter->sizes();
171 void ControllableSplitter::setShiftState(
int shiftState)
173 QList<int> sizes = mSplitter->sizes();
180 else if (shiftState>0)
187 int sizesum = sizes[0]+sizes[1];
188 sizes[0] = mSplitterRatio * sizesum;
189 sizes[1] = (1.0-mSplitterRatio) * sizesum;
191 mSplitter->setSizes(sizes);
193 this->onSplitterMoved();
196 void ControllableSplitter::shiftSplitter(
int shift)
200 int shiftState = this->getShiftState();
202 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()