Fix initial terminal size

How the initial terminal size is set:
* TerminalDisplay calculates size in pixels from requested columns/rows
  count, and uses it as the size hint.
* TabbedViewContainer, which wraps TerminalDisplay and QTabBar,
  and MainWindow, which wraps TabbedViewContainer, calculates their
  sizes from their children's size hints. It is assumed the size
  is equal to children's bounding rectangle size, eventually increased
  by visible margins.
* TerminalDisplay adjusts its size to fill the window. In this case,
  this should change nothing.

QTabWidget's (TabbedViewContainer base class) sizeHint() includes
some (*nonexistent*) margins added by widgets style (by default 2*2,
2*4 in Breeze). Those were propagated to the window size and were
increasing TerminalDisplay size.

Reimplemented TabbedViewContainer::sizeHint() returns the size of its
children's bounding rectangle.
wilder-portage
Mariusz Glebocki 7 years ago
parent 47d97aa0b3
commit efb621d091
  1. 36
      src/ViewContainer.cpp
  2. 2
      src/ViewContainer.h

@ -273,6 +273,42 @@ void TabbedViewContainer::terminalDisplayDropped(TerminalDisplay *terminalDispla
connectedViewManager()->attachView(terminalDisplay, terminalSession);
}
QSize TabbedViewContainer::sizeHint() const
{
// QTabWidget::sizeHint() contains some margins added by widgets
// style, which were making the initial window size too big.
const auto tabsSize = tabBar()->sizeHint();
const auto *leftWidget = cornerWidget(Qt::TopLeftCorner);
const auto *rightWidget = cornerWidget(Qt::TopRightCorner);
const auto leftSize = leftWidget ? leftWidget->sizeHint() : QSize(0, 0);
const auto rightSize = rightWidget ? rightWidget->sizeHint() : QSize(0, 0);
auto tabBarSize = QSize(0, 0);
// isVisible() won't work; this is called when the window is not yet visible
if (tabBar()->isVisibleTo(this)) {
tabBarSize.setWidth(leftSize.width() + tabsSize.width() + rightSize.width());
tabBarSize.setHeight(qMax(tabsSize.height(), qMax(leftSize.height(), rightSize.height())));
}
const auto terminalSize = currentWidget() ? currentWidget()->sizeHint() : QSize(0, 0);
// width
// ├──────────────────┤
//
// ┌──────────────────┐ ┬
// │ │ │
// │ Terminal │ │
// │ │ │ height
// ├───┬──────────┬───┤ │ ┬
// │ L │ Tabs │ R │ │ │ tab bar height
// └───┴──────────┴───┘ ┴ ┴
//
// L/R = left/right widget
return QSize(qMax(terminalSize.width(), tabBarSize.width()),
tabBarSize.height() + terminalSize.height());
}
void TabbedViewContainer::addSplitter(ViewSplitter *viewSplitter, int index) {
if (index == -1) {
index = addTab(viewSplitter, QString());

@ -163,6 +163,8 @@ public:
void setNavigationBehavior(int behavior);
void terminalDisplayDropped(TerminalDisplay* terminalDisplay);
QSize sizeHint() const override;
Q_SIGNALS:
/** Emitted when the container has no more children */
void empty(TabbedViewContainer *container);

Loading…
Cancel
Save