Skip to content

Commit

Permalink
Adding cursors for different mouse modes
Browse files Browse the repository at this point in the history
  • Loading branch information
John Harwell committed Apr 6, 2012
1 parent 73b7ff0 commit 66a8048
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 37 deletions.
9 changes: 9 additions & 0 deletions notes/images.txt
@@ -0,0 +1,9 @@


Use a PNG image and place the image in the directory src/Desktop/images directory. In the same directory, edit the file resources.qrc and add the image.

In the code, to load the image, use one of the "load" methods in WuQtUtilities.

In the load methods, prefix the file name with ":/" which tells Qt that the image should be loaded from resources.

Delete Desktop from your build directory, rerun cmake, and then build. This step must be done after images.qrc has been edited or touched.
Binary file added src/Desktop/images/cursor_pen_eraser_32x32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Desktop/images/images.qrc
Expand Up @@ -16,7 +16,7 @@
<file>view-right-medial.png</file>
<file>toolbar.png</file>
<file>toolbox.png</file>

<file>cursor_pen_eraser_32x32.png</file>
</qresource>
</RCC>

11 changes: 11 additions & 0 deletions src/GuiQt/BrainOpenGLWidget.cxx
Expand Up @@ -190,6 +190,17 @@ BrainOpenGLWidget::clearDrawingViewportContents()
void
BrainOpenGLWidget::paintGL()
{
/*
* Set the cursor to that requested by the user input processor
*/
QCursor userInputCursor;
if (this->selectedUserInputProcessor->getCursor(userInputCursor)) {
this->setCursor(userInputCursor);
}
else {
this->unsetCursor();
}

this->clearDrawingViewportContents();

int viewport[4] = {
Expand Down
6 changes: 3 additions & 3 deletions src/GuiQt/BrainOpenGLWidgetContextMenu.cxx
Expand Up @@ -46,7 +46,7 @@
#include "BrowserTabContent.h"
#include "ConnectivityLoaderFile.h"
#include "ConnectivityLoaderManager.h"
#include "CursorDisplay.h"
#include "CursorDisplayScoped.h"
#include "EventManager.h"
#include "EventIdentificationSymbolRemoval.h"
#include "EventInformationTextDisplay.h"
Expand Down Expand Up @@ -305,7 +305,7 @@ BrainOpenGLWidgetContextMenu::parcelConnectivityActionSelected(QAction* action)
}

try {
CursorDisplay cursor(Qt::WaitCursor);
CursorDisplayScoped cursor(Qt::WaitCursor);
pc->connectivityLoaderManager->loadAverageDataForSurfaceNodes(pc->surface,
nodeIndices);
}
Expand Down Expand Up @@ -357,7 +357,7 @@ BrainOpenGLWidgetContextMenu::borderConnectivitySelected()
}

try {
CursorDisplay cursor(Qt::WaitCursor);
CursorDisplayScoped cursor(Qt::WaitCursor);
ConnectivityLoaderManager* connectivityLoaderManager = borderID->getBrain()->getConnectivityLoaderManager();
connectivityLoaderManager->loadAverageDataForSurfaceNodes(surface,
nodeIndices);
Expand Down
6 changes: 4 additions & 2 deletions src/GuiQt/CMakeLists.txt
Expand Up @@ -104,7 +104,8 @@ ClassAndNameHierarchyViewController.h
ColorEditorWidget.h
ConnectivityLoaderControl.h
ConnectomeDBBrowserWindow.h
CursorDisplay.h
CursorDisplayScoped.h
CursorManager.h
DisplayControlDialog.h
DisplayControlVolumeSurfaceOutlinePage.h
DisplayGroupEnumComboBox.h
Expand Down Expand Up @@ -177,7 +178,8 @@ ClassAndNameHierarchyViewController.cxx
ColorEditorWidget.cxx
ConnectivityLoaderControl.cxx
ConnectomeDBBrowserWindow.cxx
CursorDisplay.cxx
CursorDisplayScoped.cxx
CursorManager.cxx
DisplayControlDialog.cxx
DisplayControlVolumeSurfaceOutlinePage.cxx
DisplayGroupEnumComboBox.cxx
Expand Down
44 changes: 29 additions & 15 deletions src/GuiQt/CursorDisplay.cxx → src/GuiQt/CursorDisplayScoped.cxx
Expand Up @@ -34,39 +34,53 @@

#include <QApplication>

#define __CURSOR_DISPLAY_DECLARE__
#include "CursorDisplay.h"
#undef __CURSOR_DISPLAY_DECLARE__
#define __CURSOR_DISPLAY_SCOPED_DECLARE__
#include "CursorDisplayScoped.h"
#undef __CURSOR_DISPLAY_SCOPED_DECLARE__

#include "CursorManager.h"
#include "GuiManager.h"

using namespace caret;


/**
* \class caret::CursorDisplay
* \brief Displays a cursor
* \class caret::CursorDisplayScoped
* \brief Displays a override cursor
*
* Displays a cursor that overrides all other cursors in the
* application until an instance goes out of scope or the
* method restoreCursor() is called.
*/

/**
* Constructor that displays a wait cursor.
*
* Displays a cursor that will remain displayed until this
* instance goes out of scope or the method restoreCursor()
* is called.
*/
CursorDisplayScoped::CursorDisplayScoped()
: CaretObject()
{
QApplication::setOverrideCursor(GuiManager::get()->getCursorManager()->getWaitCursor());
QApplication::processEvents();
}

/**
* Constructor.
* Constructor for display of a specific cursor.
*
* @param cursorShape
* @param cursor
* Cursor that is displayed.
*/
CursorDisplay::CursorDisplay(const Qt::CursorShape cursorShape)
CursorDisplayScoped::CursorDisplayScoped(const QCursor& cursor)
: CaretObject()
{
QApplication::setOverrideCursor(QCursor(cursorShape));
QApplication::setOverrideCursor(cursor);
QApplication::processEvents();
}

/**
* Destructor.
*/
CursorDisplay::~CursorDisplay()
CursorDisplayScoped::~CursorDisplayScoped()
{
this->restoreCursor();
}
Expand All @@ -75,7 +89,7 @@ CursorDisplay::~CursorDisplay()
* Restore the default cursor.
*/
void
CursorDisplay::restoreCursor()
CursorDisplayScoped::restoreCursor()
{
QApplication::restoreOverrideCursor();
}
Expand All @@ -86,7 +100,7 @@ CursorDisplay::restoreCursor()
* @return String describing this object's content.
*/
AString
CursorDisplay::toString() const
CursorDisplayScoped::toString() const
{
return "CursorDisplay";
}
26 changes: 14 additions & 12 deletions src/GuiQt/CursorDisplay.h → src/GuiQt/CursorDisplayScoped.h
@@ -1,5 +1,5 @@
#ifndef __CURSOR_DISPLAY__H_
#define __CURSOR_DISPLAY__H_
#ifndef __CURSOR_DISPLAY_SCOPED_H_
#define __CURSOR_DISPLAY_SCOPED_H_

/*LICENSE_START*/
/*
Expand Down Expand Up @@ -34,35 +34,37 @@
*/
/*LICENSE_END*/

#include <Qt>

#include "CaretObject.h"

class QCursor;

namespace caret {

class CursorDisplay : public CaretObject {
class CursorDisplayScoped : public CaretObject {

public:
CursorDisplay(const Qt::CursorShape cursorShape);
CursorDisplayScoped();

CursorDisplayScoped(const QCursor& cursor);

void restoreCursor();

virtual ~CursorDisplay();
virtual ~CursorDisplayScoped();

private:
CursorDisplay(const CursorDisplay&);
CursorDisplayScoped(const CursorDisplayScoped&);

CursorDisplay& operator=(const CursorDisplay&);
CursorDisplayScoped& operator=(const CursorDisplayScoped&);

public:
virtual AString toString() const;

private:
};

#ifdef __CURSOR_DISPLAY_DECLARE__
#ifdef __CURSOR_DISPLAY_SCOPED_DECLARE__
// <PLACE DECLARATIONS OF STATIC MEMBERS HERE>
#endif // __CURSOR_DISPLAY_DECLARE__
#endif __CURSOR_DISPLAY_SCOPED_DECLARE__

} // namespace
#endif //__CURSOR_DISPLAY__H_
#endif //__CURSOR_DISPLAY_SCOPED__H_
146 changes: 146 additions & 0 deletions src/GuiQt/CursorManager.cxx
@@ -0,0 +1,146 @@

/*LICENSE_START*/
/*
* Copyright 2012 Washington University,
* All rights reserved.
*
* Connectome DB and Connectome Workbench are part of the integrated Connectome
* Informatics Platform.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of Washington University nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*LICENSE_END*/

#include <QPixmap>

#define __CURSOR_MANAGER_DECLARE__
#include "CursorManager.h"
#undef __CURSOR_MANAGER_DECLARE__

#include "WuQtUtilities.h"

using namespace caret;



/**
* \class caret::CursorManager
* \brief Manages cursors
*
* Provides cursors, some predefined by Qt and
* others unique to workbench.
*/

/**
* Constructor.
*/
CursorManager::CursorManager()
: CaretObject()
{
this->defaultCursor = QCursor();
this->penCursor = this->loadCursor(":/cursor_pen_eraser_32x32.png",
6,
32 - 7,
Qt::UpArrowCursor);
this->pointingHandCursor = QCursor(Qt::PointingHandCursor);
this->waitCursor = QCursor(Qt::WaitCursor);
}

/**
* Destructor.
*/
CursorManager::~CursorManager()
{

}

/**
* Load an image and create a cursor using the image.
*
* @param filename
* Name of file containing the image.
* @param hotSpotX
* Hot spot (location in cursor reported to GUI)
* @param hotSpotY
* Hot spot (location in cursor reported to GUI)
* @param cursorShapeIfImageLoadingFails
* Cursor shape used if loading the image fails.
* @return
* Cursor that was created.
*/
QCursor
CursorManager::loadCursor(const QString& filename,
const int hotSpotX,
const int hotSpotY,
const Qt::CursorShape& cursorShapeIfImageLoadingFails) const
{
QPixmap cursorPixmap;
if (WuQtUtilities::loadPixmap(filename, cursorPixmap)) {
QCursor cursor(cursorPixmap,
hotSpotX,
hotSpotY);
return cursor;
}

return QCursor(cursorShapeIfImageLoadingFails);
}


/**
* @return The default cursor.
*/
const QCursor&
CursorManager::getDefaultCursor() const
{
return this->defaultCursor;
}

/**
* @return The pen cursor.
*/
const QCursor&
CursorManager::getPenCursor() const
{
return this->penCursor;
}

/**
* @return The pointing hand cursor.
*/
const QCursor&
CursorManager::getPointingHandCursor() const
{
return this->pointingHandCursor;
}

/**
* @return The wait cursor.
*/
const QCursor&
CursorManager::getWaitCursor() const
{
return this->waitCursor;
}


0 comments on commit 66a8048

Please sign in to comment.