[apps] Improve title bar view layout

Change-Id: I67e714cc94fd100270cf5488602de1fd5cfce27e
This commit is contained in:
Émilie Feral
2017-04-26 15:09:26 +02:00
parent 2968183121
commit 5595a3f4c5
2 changed files with 15 additions and 2 deletions

View File

@@ -16,6 +16,12 @@ TitleBarView::TitleBarView() :
m_examModeIconView.setImage(ImageStore::ExamIcon);
}
void TitleBarView::drawRect(KDContext * ctx, KDRect rect) const {
/* As we cheated to layout the title view, we have to fill a very thin
* rectangle at the top with the background color. */
ctx->fillRect(KDRect(0, 0, bounds().width(), 2), Palette::YellowDark);
}
void TitleBarView::setTitle(I18n::Message title) {
m_titleView.setMessage(title);
}
@@ -46,8 +52,13 @@ View * TitleBarView::subviewAtIndex(int index) {
}
void TitleBarView::layoutSubviews() {
m_titleView.setFrame(bounds());
m_preferenceView.setFrame(KDRect(0, 0, m_preferenceView.minimalSizeForOptimalDisplay()));
/* We here cheat to layout the main title. The application title is written
* with upper cases. But, as upper letters are on the same baseline as lower
* letters, they seem to be slightly above when they are perferctly centered
* (because their glyph never cross the baseline). To avoid this effect, we
* translate the frame of the title downwards.*/
m_titleView.setFrame(KDRect(0, 2, bounds().width(), bounds().height()-2));
m_preferenceView.setFrame(KDRect(k_preferenceMargin, 0, m_preferenceView.minimalSizeForOptimalDisplay().width(), bounds().height()));
KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay();
m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize));
if (GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) {

View File

@@ -8,12 +8,14 @@
class TitleBarView : public View {
public:
TitleBarView();
void drawRect(KDContext * ctx, KDRect rect) const override;
void setTitle(I18n::Message title);
bool setChargeState(Ion::Battery::Charge chargeState);
bool setIsCharging(bool isCharging);
void refreshPreferences();
private:
constexpr static KDCoordinate k_batteryLeftMargin = 5;
constexpr static KDCoordinate k_preferenceMargin = 3;
constexpr static KDCoordinate k_examIconWidth = 18;
constexpr static KDCoordinate k_examIconHeight = 9;
constexpr static KDCoordinate k_examIconMargin = 93;