Skip to content

Commit

Permalink
- Library drag implementation is changed.
Browse files Browse the repository at this point in the history
- UserManual opening code is updated.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7544 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Dec 21, 2010
1 parent 63a7289 commit 6295b40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 54 deletions.
69 changes: 22 additions & 47 deletions OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -394,7 +394,6 @@ LibraryTreeNode::LibraryTreeNode(QString text, QString parentName, QString toolt
LibraryTree::LibraryTree(LibraryWidget *pParent)
: QTreeWidget(pParent)
{
mItemExpandCollapseClicked = false;
mpParentLibraryWidget = pParent;

setFrameShape(QFrame::NoFrame);
Expand All @@ -407,8 +406,8 @@ LibraryTree::LibraryTree(LibraryWidget *pParent)
setContextMenuPolicy(Qt::CustomContextMenu);
createActions();

connect(this, SIGNAL(itemPressed(QTreeWidgetItem*,int)), SLOT(treeItemPressed(QTreeWidgetItem*)));
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(expandLib(QTreeWidgetItem*)));
connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), SLOT(collapseLib(QTreeWidgetItem*)));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(showComponent(QTreeWidgetItem*,int)));
}
Expand Down Expand Up @@ -600,10 +599,8 @@ bool LibraryTree::sortNodesAscending(const LibraryTreeNode *node1, const Library

//! Makes a library expand.
//! @param item is the library to show.
//! @see collapseLib(QTreeWidgetItem *item)
void LibraryTree::expandLib(QTreeWidgetItem *item)
{
mItemExpandCollapseClicked = true;
if (isTreeItemLoaded(item))
{
mTreeList.append(item->toolTip(0));
Expand Down Expand Up @@ -635,15 +632,6 @@ void LibraryTree::expandLib(QTreeWidgetItem *item)
// unsetCursor();
}

//! Makes a library collapse.
//! @param item is the library to show.
//! @see collapseLib(QTreeWidgetItem *item)
void LibraryTree::collapseLib(QTreeWidgetItem *item)
{
Q_UNUSED(item);
mItemExpandCollapseClicked = true;
}

void LibraryTree::showContextMenu(QPoint point)
{
int adjust = 24;
Expand Down Expand Up @@ -714,49 +702,36 @@ void LibraryTree::loadingLibraryComponent(LibraryTreeNode *treeNode, QString cla
mpParentLibraryWidget->addComponentObject(libComponent);
}

void LibraryTree::mousePressEvent(QMouseEvent *event)
void LibraryTree::treeItemPressed(QTreeWidgetItem *item)
{
QTreeWidget::mousePressEvent(event);

// if user has clicked on the expand/collapse button then return simply.
if (mItemExpandCollapseClicked)
{
mItemExpandCollapseClicked = false;
if (!item)
return;
}

if ((event->button() == Qt::LeftButton))
{
QTreeWidgetItem *item = static_cast<QTreeWidgetItem*>(itemAt(event->pos()));
if (!item)
return;

// if item is package then return
// if (mpParentLibraryWidget->mpParentMainWindow->mpOMCProxy->isWhat(StringHandler::PACKAGE, item->toolTip(0)))
// return;
// if item is package then return
// if (mpParentLibraryWidget->mpParentMainWindow->mpOMCProxy->isWhat(StringHandler::PACKAGE, item->toolTip(0)))
// return;

QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << item->toolTip(0);
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << item->toolTip(0);

QMimeData *mimeData = new QMimeData;
mimeData->setData("image/modelica-component", itemData);
QMimeData *mimeData = new QMimeData;
mimeData->setData("image/modelica-component", itemData);

qreal adjust = 35;
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
qreal adjust = 35;
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);

// get the component SVG to show on drag
LibraryComponent *libraryComponent = mpParentLibraryWidget->getLibraryComponentObject(item->toolTip(0));
// get the component SVG to show on drag
LibraryComponent *libraryComponent = mpParentLibraryWidget->getLibraryComponentObject(item->toolTip(0));

if (libraryComponent)
{
QPixmap pixmap = libraryComponent->getComponentPixmap(QSize(50, 50));
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint((drag->hotSpot().x() + adjust), (drag->hotSpot().y() + adjust)));
}
drag->exec(Qt::CopyAction);
if (libraryComponent)
{
QPixmap pixmap = libraryComponent->getComponentPixmap(QSize(50, 50));
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint((drag->hotSpot().x() + adjust), (drag->hotSpot().y() + adjust)));
}
drag->exec(Qt::CopyAction);
}

//! Constructor.
Expand Down
7 changes: 3 additions & 4 deletions OMEdit/OMEditGUI/LibraryWidget.h
Expand Up @@ -117,7 +117,6 @@ class LibraryTree : public QTreeWidget
Q_OBJECT
private:
QList<QString> mTreeList;
bool mItemExpandCollapseClicked;

QAction *mpShowComponentAction;
QAction *mpViewDocumentationAction;
Expand All @@ -138,15 +137,15 @@ class LibraryTree : public QTreeWidget
LibraryWidget *mpParentLibraryWidget;
private slots:
void expandLib(QTreeWidgetItem *item);
void collapseLib(QTreeWidgetItem *item);
void showContextMenu(QPoint point);
void showComponent(QTreeWidgetItem *item, int column);
void showComponent();
void viewDocumentation();
void checkLibraryModel();
void loadingLibraryComponent(LibraryTreeNode *treeNode, QString className);
protected:
virtual void mousePressEvent(QMouseEvent *event);
void treeItemPressed(QTreeWidgetItem *item);
//protected:
// virtual void mousePressEvent(QMouseEvent *event);
};

class LibraryWidget : public QWidget
Expand Down
8 changes: 5 additions & 3 deletions OMEdit/OMEditGUI/mainwindow.cpp
Expand Up @@ -605,9 +605,11 @@ void MainWindow::checkModel()

void MainWindow::openUserManual()
{
QString userManualPath;
userManualPath = QString(Helper::OpenModelicaHome.replace("\\", "/"))
.append("/share/doc/omedit/OMEdit-UserManual.pdf");
// QString userManualPath;
// userManualPath = >QString(Helper::OpenModelicaHome.replace("\\", "/"))
// .append("/share/doc/omedit/OMEdit-UserManual.pdf");
QUrl userManualPath (QString("file:///").append(Helper::OpenModelicaHome.replace("\\", "/"))
.append("/share/doc/omedit/OMEdit-UserManual.pdf"));
QDesktopServices::openUrl(userManualPath);
}

Expand Down

0 comments on commit 6295b40

Please sign in to comment.