Files
Sourcetrail/src/lib_gui/qt/element/QtPathListBox.cpp
T
mlangkabel dfc6d88432 build: search headers in all source directories
* removed paths in include directives
* changed cmake to provide necessary header search paths
* changed name of version.h to productVersion.h due to name conflict
2018-09-18 19:00:18 +02:00

102 lines
2.4 KiB
C++

#include "QtPathListBox.h"
#include <QtGui/qevent.h>
#include <QLabel>
#include <QListWidget>
#include <QMimeData>
#include "QtPathListBoxItem.h"
#include "utilityFile.h"
QtPathListBox::QtPathListBox(QWidget *parent, const QString& listName, SelectionPolicyType selectionPolicy)
: QtListBox(parent, listName)
, m_selectionPolicy(selectionPolicy)
{
QLabel* dropInfoText = new QLabel("Drop Files & Folders");
dropInfoText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
dropInfoText->setObjectName("dropInfo");
dropInfoText->setAlignment(Qt::AlignRight);
addWidgetToBar(dropInfoText);
}
QtPathListBox::SelectionPolicyType QtPathListBox::getSelectionPolicy() const
{
return m_selectionPolicy;
}
const FilePath& QtPathListBox::getRelativeRootDirectory() const
{
return m_relativeRootDirectory;
}
void QtPathListBox::setRelativeRootDirectory(const FilePath& dir)
{
m_relativeRootDirectory = dir;
}
std::vector<FilePath> QtPathListBox::getPathsAsDisplayed() const
{
std::vector<FilePath> paths;
for (int i = 0; i < m_list->count(); ++i)
{
QtListBoxItem* widget = dynamic_cast<QtListBoxItem*>(m_list->itemWidget(m_list->item(i)));
paths.push_back(FilePath(widget->getText().toStdWString()));
}
return paths;
}
std::vector<FilePath> QtPathListBox::getPathsAsAbsolute() const
{
std::vector<FilePath> paths = getPathsAsDisplayed();
for (FilePath& path: paths)
{
makeAbsolute(path);
}
return paths;
}
void QtPathListBox::setPaths(const std::vector<FilePath>& list, bool readOnly)
{
clear();
for (FilePath path : list)
{
QtListBoxItem* item = addListBoxItemWithText(QString::fromStdWString(path.wstr()));
item->setReadOnly(readOnly);
}
}
void QtPathListBox::makeAbsolute(FilePath& path) const
{
if (!path.empty() && !path.isAbsolute() && !m_relativeRootDirectory.empty())
{
path = m_relativeRootDirectory.getConcatenated(path);
}
}
void QtPathListBox::makeRelativeIfShorter(FilePath& path) const
{
path = utility::getAsRelativeIfShorter(path, m_relativeRootDirectory);
}
void QtPathListBox::dropEvent(QDropEvent *event)
{
foreach(QUrl url, event->mimeData()->urls())
{
FilePath path(url.toLocalFile().toStdWString());
makeRelativeIfShorter(path);
addListBoxItemWithText(QString::fromStdWString(path.wstr()));
}
}
void QtPathListBox::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();
}
QtListBoxItem* QtPathListBox::createListBoxItem(QListWidgetItem* item)
{
return new QtPathListBoxItem(this, item);
}