1 /* 2 outline_view.cpp MindForger thinking notebook 3 4 Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com> 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #include "outline_view.h" 20 21 namespace m8r { 22 23 using namespace std; 24 OutlineView(QWidget * parent)25OutlineView::OutlineView(QWidget *parent) 26 : QWidget(parent) 27 { 28 // KISS & ONCE: show the name only - details to be rendered by Outline header view 29 nameLabel = new OutlineNamePushButton{parent}; 30 nameLabel->sizePolicy().setHorizontalPolicy(QSizePolicy::Maximum); 31 nameLabel->setToolTip(tr("Click this Notebook name to open its Markdown preview in the right panel")); 32 // make button to look like label 33 nameLabel->setStyleSheet("QPushButton{ border: 0px; }"); 34 #ifdef NO_LONGER_NEEDED 35 string css{}; 36 css += "QPushButton{ border: 0px; } QPushButton:hover{ background-color:"; 37 css += LookAndFeels::getInstance().getHighlightColor().toStdString(); 38 css += "; }"; 39 nameLabel->setStyleSheet(QString::fromStdString(css)); 40 #endif 41 QFont nameFont = nameLabel->font(); 42 nameFont.setPointSize(nameFont.pointSize()+nameFont.pointSize()/4); 43 nameFont.setBold(true); 44 // subjective - this is too much: nameFont.setUnderline(true); 45 nameLabel->setFont(nameFont); 46 headerVerticalLayout.addWidget(nameLabel); 47 48 // tree of Ns 49 outlineTreeView = new OutlineTreeView(parent); 50 headerVerticalLayout.addWidget(outlineTreeView); 51 52 setLayout(&headerVerticalLayout); 53 } 54 ~OutlineView()55OutlineView::~OutlineView() 56 { 57 } 58 refreshHeader(const std::string & name)59void OutlineView::refreshHeader(const std::string& name) 60 { 61 if(!name.empty()) { 62 QFontMetrics metrics(nameLabel->font()); 63 // IMPROVE nameLabel has incorrect size before rendered for the first time - find a better solution than fixed width 64 QString elidedText 65 = metrics.elidedText( 66 QString::fromStdString(name), 67 Qt::ElideRight, 68 width()-20); 69 nameLabel->setText(elidedText); 70 } else { 71 nameLabel->setText(""); 72 } 73 } 74 75 } // m8r namespace 76