File indexing completed on 2024-04-14 04:31:15

0001 /*
0002  * This file is part of KDevelop
0003  *
0004  * Copyright (C) 2014-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0005  *
0006  * This program is free software: you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation, either version 3 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #include <rails/quickopendata.h>
0021 
0022 #include <QtGui/QIcon>
0023 #include <QtGui/QTextCharFormat>
0024 
0025 #include <interfaces/icore.h>
0026 #include <interfaces/idocumentcontroller.h>
0027 
0028 #include <rails/helpers.h>
0029 
0030 using namespace ruby::rails;
0031 
0032 QuickOpenData::QuickOpenData(const QuickOpenItem &item,
0033                              const QString &explanation)
0034     : QuickOpenDataBase()
0035     , m_item(item), m_explanation(explanation)
0036 {
0037 }
0038 
0039 QString QuickOpenData::text() const
0040 {
0041     const QString &item = m_item.url.toString();
0042     return KDevelop::Path(Helpers::findRailsRoot(m_item.url), item).path();
0043 }
0044 
0045 QString QuickOpenData::htmlDescription() const
0046 {
0047     return "<small><small>" + m_explanation + ' '
0048             + m_item.originUrl.fileName() + "</small></small>";
0049 }
0050 
0051 bool QuickOpenData::execute(QString &filterText)
0052 {
0053     Q_UNUSED(filterText);
0054 
0055     KDevelop::ICore::self()->documentController()->openDocument(m_item.url);
0056     return true;
0057 }
0058 
0059 bool QuickOpenData::isExpandable() const
0060 {
0061     return false;
0062 }
0063 
0064 QWidget * QuickOpenData::expandingWidget() const
0065 {
0066     return KDevelop::QuickOpenDataBase::expandingWidget();
0067 }
0068 
0069 QIcon QuickOpenData::icon() const
0070 {
0071     return KDevelop::QuickOpenDataBase::icon();
0072 }
0073 
0074 QList<QVariant> QuickOpenData::highlighting() const
0075 {
0076     QTextCharFormat boldFormat;
0077     boldFormat.setFontWeight(QFont::Bold);
0078 
0079     const QString &txt = text();
0080     int fileNameLength = m_item.url.fileName().length();
0081 
0082     return QList<QVariant>{
0083         0,
0084         txt.length() - fileNameLength,
0085         QVariant(QTextCharFormat()),
0086         txt.length() - fileNameLength,
0087         fileNameLength,
0088         QVariant(boldFormat)
0089     };
0090 }
0091