Skip to content

Commit

Permalink
Merge pull request #22 from rdumusc/newapi
Browse files Browse the repository at this point in the history
Improved server api class names. Using common code style guidelines.
  • Loading branch information
Raphael Dumusc committed Jun 23, 2015
2 parents 5066e52 + 43b787e commit 12909a5
Show file tree
Hide file tree
Showing 74 changed files with 2,355 additions and 2,133 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
include(GitExternal)

set(VERSION_MAJOR "0")
set(VERSION_MINOR "5")
set(VERSION_PATCH "1")
set(VERSION_MINOR "6")
set(VERSION_PATCH "0")
set(VERSION_ABI 1)

set(DEFLECT_DESCRIPTION
Expand Down
44 changes: 41 additions & 3 deletions apps/DesktopStreamer/AppNapSuspender.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
/*********************************************************************/
/* Copyright (c) 2014-2015, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* 1. Redistributions of source code must retain the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer. */
/* */
/* 2. 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. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
/* AUSTIN ``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 UNIVERSITY OF TEXAS AT */
/* AUSTIN 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. */
/* */
/* The views and conclusions contained in the software and */
/* documentation are those of the authors and should not be */
/* interpreted as representing official policies, either expressed */
/* or implied, of The University of Texas at Austin. */
/*********************************************************************/

#ifndef APPNAPSUSPENDER_H
#define APPNAPSUSPENDER_H

class AppNapSuspenderPrivate;

/**
* Suspend AppNap on OSX >= 10.9.
*/
Expand All @@ -22,7 +59,8 @@ class AppNapSuspender
void resume();

private:
AppNapSuspenderPrivate* impl_;
class Impl;
Impl* _impl;
};

#endif // APPNAPSUSPENDER_H
67 changes: 53 additions & 14 deletions apps/DesktopStreamer/AppNapSuspender.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
/*********************************************************************/
/* Copyright (c) 2014-2015, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* 1. Redistributions of source code must retain the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer. */
/* */
/* 2. 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. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
/* AUSTIN ``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 UNIVERSITY OF TEXAS AT */
/* AUSTIN 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. */
/* */
/* The views and conclusions contained in the software and */
/* documentation are those of the authors and should not be */
/* interpreted as representing official policies, either expressed */
/* or implied, of The University of Texas at Austin. */
/*********************************************************************/

#include "AppNapSuspender.h"

#include <Foundation/NSProcessInfo.h>
Expand All @@ -13,48 +52,48 @@
#endif
#endif

class AppNapSuspenderPrivate
class AppNapSuspender::Impl
{
public:
AppNapSuspenderPrivate()
: activityId(nil)
Impl()
: activityId( nil )
{}

id<NSObject> activityId;
};

AppNapSuspender::AppNapSuspender() :
impl_(new AppNapSuspenderPrivate)
_impl( new Impl )
{
}

AppNapSuspender::~AppNapSuspender()
{
resume();
delete impl_;
delete _impl;
}

void AppNapSuspender::suspend()
{
if (impl_->activityId)
if( _impl->activityId )
return;

if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)])
if( [[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)] )
{
impl_->activityId = [[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiated reason:@"Good reason"];
[impl_->activityId retain];
_impl->activityId = [[NSProcessInfo processInfo] beginActivityWithOptions: NSActivityUserInitiated reason:@"Good reason"];
[_impl->activityId retain];
}
}

void AppNapSuspender::resume()
{
if(!impl_->activityId)
if( !_impl->activityId )
return;

if([[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)])
if( [[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)] )
{
[[NSProcessInfo processInfo] endActivity:impl_->activityId];
[impl_->activityId release];
impl_->activityId = nil;
[[NSProcessInfo processInfo] endActivity:_impl->activityId];
[_impl->activityId release];
_impl->activityId = nil;
}
}
88 changes: 43 additions & 45 deletions apps/DesktopStreamer/DesktopSelectionRectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,91 +38,89 @@

#include "DesktopSelectionRectangle.h"

#include <cmath>

#define PEN_WIDTH 10 // should be even
#define CORNER_RESIZE_THRESHHOLD 50
#define CORNER_RESIZE_THRESHOLD 50
#define DEFAULT_SIZE 100

DesktopSelectionRectangle::DesktopSelectionRectangle()
: resizing_(false)
, coordinates_(0, 0, DEFAULT_SIZE, DEFAULT_SIZE)
: _resizing( false )
{
// graphics items are movable
setFlag(QGraphicsItem::ItemIsMovable, true);

// default pen
setPen(QPen(QBrush(QColor(255, 0, 0)), PEN_WIDTH));

// current coordinates, accounting for width of the pen outline
setRect(coordinates_.x()-PEN_WIDTH/2, coordinates_.y()-PEN_WIDTH/2,
coordinates_.width()+PEN_WIDTH, coordinates_.height()+PEN_WIDTH);
setFlag( QGraphicsItem::ItemIsMovable, true );
setPen( QPen( QBrush( QColor( 255, 0, 0 )), PEN_WIDTH ));
setCoordinates( QRect( 0, 0, DEFAULT_SIZE, DEFAULT_SIZE ));
}

void DesktopSelectionRectangle::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
void DesktopSelectionRectangle::paint( QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget )
{
QGraphicsRectItem::paint(painter, option, widget);
QGraphicsRectItem::paint( painter, option, widget );
}

void DesktopSelectionRectangle::setCoordinates(QRect coordinates)
void DesktopSelectionRectangle::setCoordinates( const QRect& coordinates )
{
coordinates_ = coordinates;
_coordinates = coordinates;

setRect(mapRectFromScene(coordinates_.x()-PEN_WIDTH/2, coordinates_.y()-PEN_WIDTH/2,
coordinates_.width()+PEN_WIDTH, coordinates_.height()+PEN_WIDTH));
setRect( mapRectFromScene( _coordinates.x() - PEN_WIDTH/2,
_coordinates.y() - PEN_WIDTH/2,
_coordinates.width() + PEN_WIDTH,
_coordinates.height() + PEN_WIDTH ));
}

void DesktopSelectionRectangle::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
void DesktopSelectionRectangle::mouseMoveEvent( QGraphicsSceneMouseEvent*
mouseEvent )
{
if(mouseEvent->buttons().testFlag(Qt::LeftButton))
if( mouseEvent->buttons().testFlag( Qt::LeftButton ))
{
if(resizing_)
if( _resizing )
{
QRectF r = rect();

r.setBottomRight(mouseEvent->pos());

setRect(r);
r.setBottomRight( mouseEvent->pos( ));
setRect( r );
}
else
{
QPointF delta = mouseEvent->pos() - mouseEvent->lastPos();

moveBy(delta.x(), delta.y());
moveBy( delta.x(), delta.y( ));
}

updateCoordinates();
emit coordinatesChanged(coordinates_);
_updateCoordinates();
emit coordinatesChanged( _coordinates );
}
}

void DesktopSelectionRectangle::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
void DesktopSelectionRectangle::mousePressEvent( QGraphicsSceneMouseEvent*
mouseEvent )
{
// item rectangle and event position
const QRectF r = rect();
const QPointF cornerPos = rect().bottomRight();
const QPointF eventPos = mouseEvent->pos();

// check to see if user clicked on the resize button
if(fabs((r.x()+r.width()) - eventPos.x()) <= CORNER_RESIZE_THRESHHOLD &&
fabs((r.y()+r.height()) - eventPos.y()) <= CORNER_RESIZE_THRESHHOLD)
if( std::abs( cornerPos.x() - eventPos.x( )) <= CORNER_RESIZE_THRESHOLD &&
std::abs( cornerPos.y() - eventPos.y( )) <= CORNER_RESIZE_THRESHOLD )
{
resizing_ = true;
_resizing = true;
}

QGraphicsItem::mousePressEvent(mouseEvent);
QGraphicsItem::mousePressEvent( mouseEvent );
}

void DesktopSelectionRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
void DesktopSelectionRectangle::mouseReleaseEvent( QGraphicsSceneMouseEvent*
mouseEvent )
{
resizing_ = false;

QGraphicsItem::mouseReleaseEvent(mouseEvent);
_resizing = false;
QGraphicsItem::mouseReleaseEvent( mouseEvent );
}

void DesktopSelectionRectangle::updateCoordinates()
void DesktopSelectionRectangle::_updateCoordinates()
{
const QRectF sceneRect = mapRectToScene(rect());
const QRectF sceneRect = mapRectToScene( rect( ));

coordinates_.setX( (int)sceneRect.x() + PEN_WIDTH/2 );
coordinates_.setY( (int)sceneRect.y() + PEN_WIDTH/2 );
coordinates_.setWidth( (int)sceneRect.width() - PEN_WIDTH );
coordinates_.setHeight( (int)sceneRect.height() - PEN_WIDTH );
_coordinates.setX( (int)sceneRect.x() + PEN_WIDTH/2 );
_coordinates.setY( (int)sceneRect.y() + PEN_WIDTH/2 );
_coordinates.setWidth( (int)sceneRect.width() - PEN_WIDTH );
_coordinates.setHeight( (int)sceneRect.height() - PEN_WIDTH );
}
23 changes: 12 additions & 11 deletions apps/DesktopStreamer/DesktopSelectionRectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#ifndef DESKTOP_SELECTION_RECTANGLE_H
#define DESKTOP_SELECTION_RECTANGLE_H

#include <deflect/config.h>

#include <QtWidgets>

class DesktopSelectionRectangle : public QObject, public QGraphicsRectItem
Expand All @@ -48,24 +50,23 @@ class DesktopSelectionRectangle : public QObject, public QGraphicsRectItem
public:
DesktopSelectionRectangle();

virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget=0);
void paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget = 0 ) final;

void setCoordinates(QRect coordinates);
void setCoordinates( const QRect& coordinates );

signals:
void coordinatesChanged(QRect coordinates);

protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
void coordinatesChanged( QRect coordinates );

private:
void updateCoordinates();
void mouseMoveEvent( QGraphicsSceneMouseEvent* event ) final;
void mousePressEvent( QGraphicsSceneMouseEvent* event ) final;
void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) final;

bool resizing_;
void _updateCoordinates();

QRect coordinates_;
bool _resizing;
QRect _coordinates;
};

#endif
Loading

0 comments on commit 12909a5

Please sign in to comment.