{
//in case of window resize we have to hide widget so we'll fall in first case(see below) and set push button as unchecked
if(ui->widget->isVisible()){
ui->widget->setHidden(true);
ui->button->setChecked(false);
}
}
void MainWindow::showWidget()
{
//There are 2 cases:
// 1. Widget was never shown before,
// 2.Widget was shown (at least) once and then hide again,
if(ui->widget->isHidden()){
//If the widget is hidden then we're in the first case.
//We set up y coord of starting transition to a bigger value than height coord and all other
//coords at the widget's coords; while we have to set up final transition coords to widget's coords.
//In this way it'll look like upward motion.
//PLEASE NOTE: before you have to perform ui->widget->show() and then get widget's size() and pos(), else you'll get wrong values.
ui->widget->show();
QPoint pos
= ui
->widget
->pos
();
QSize size
= ui
->widget
->size
();
fo
= QRect(pos.
x(),pos.
y()+size.
height(),size.
width(),size.
height());
}else{
//in second case: we have to set up start transition coords at actual coords of widget, as it's hidden
//we would have y = y + height, and we set up y coord of final transition coords to y = y - height.
fo = ui->widget->geometry();
fi
= QRect(fo.
x(),fo.
y()-fo.
height(),fo.
width(),fo.
height());
}
QPropertyAnimation *showAnimation = new QPropertyAnimation(ui->widget, "geometry");
showAnimation->setDuration(100);
showAnimation->setEasingCurve(QEasingCurve::Linear);
showAnimation->setStartValue(fo);
showAnimation->setEndValue(fi);
showAnimation->start(QPropertyAnimation::DeleteWhenStopped);
}
void MainWindow::hideWidget()
{
//coords of starting transition must be set up at actual widget's coords, as it's visible; while final
//transition coords must be set up with: y = y + height.
QRect fi
= QRect(fo.
x(),fo.
y()+fo.
height(),fo.
width(),fo.
height());
QPropertyAnimation *hideAnimation = new QPropertyAnimation(ui->widget, "geometry");
hideAnimation->setDuration(100);
hideAnimation->setEasingCurve(QEasingCurve::Linear);
hideAnimation->setStartValue(fo);
hideAnimation->setEndValue(fi);
hideAnimation->start(QPropertyAnimation::DeleteWhenStopped);
}
void MainWindow::togglePyShell(bool show)
{
if(show){
showWidget();
}else{
hideWidget();
}
}
void MainWindow::resizeEvent(QResizeEvent *)
{
//in case of window resize we have to hide widget so we'll fall in first case(see below) and set push button as unchecked
if(ui->widget->isVisible()){
ui->widget->setHidden(true);
ui->button->setChecked(false);
}
}
void MainWindow::showWidget()
{
QRect fo;
QRect fi;
//There are 2 cases:
// 1. Widget was never shown before,
// 2.Widget was shown (at least) once and then hide again,
if(ui->widget->isHidden()){
//If the widget is hidden then we're in the first case.
//We set up y coord of starting transition to a bigger value than height coord and all other
//coords at the widget's coords; while we have to set up final transition coords to widget's coords.
//In this way it'll look like upward motion.
//PLEASE NOTE: before you have to perform ui->widget->show() and then get widget's size() and pos(), else you'll get wrong values.
ui->widget->show();
QPoint pos = ui->widget->pos();
QSize size = ui->widget->size();
fo = QRect(pos.x(),pos.y()+size.height(),size.width(),size.height());
fi = QRect(pos,size);
}else{
//in second case: we have to set up start transition coords at actual coords of widget, as it's hidden
//we would have y = y + height, and we set up y coord of final transition coords to y = y - height.
fo = ui->widget->geometry();
fi = QRect(fo.x(),fo.y()-fo.height(),fo.width(),fo.height());
}
QPropertyAnimation *showAnimation = new QPropertyAnimation(ui->widget, "geometry");
showAnimation->setDuration(100);
showAnimation->setEasingCurve(QEasingCurve::Linear);
showAnimation->setStartValue(fo);
showAnimation->setEndValue(fi);
showAnimation->start(QPropertyAnimation::DeleteWhenStopped);
}
void MainWindow::hideWidget()
{
//coords of starting transition must be set up at actual widget's coords, as it's visible; while final
//transition coords must be set up with: y = y + height.
QRect fo = QRect(ui->widget->geometry());
QRect fi = QRect(fo.x(),fo.y()+fo.height(),fo.width(),fo.height());
QPropertyAnimation *hideAnimation = new QPropertyAnimation(ui->widget, "geometry");
hideAnimation->setDuration(100);
hideAnimation->setEasingCurve(QEasingCurve::Linear);
hideAnimation->setStartValue(fo);
hideAnimation->setEndValue(fi);
hideAnimation->start(QPropertyAnimation::DeleteWhenStopped);
}
void MainWindow::togglePyShell(bool show)
{
if(show){
showWidget();
}else{
hideWidget();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks